From b35d10bae7315fe3e497f1188bbe5ce86cef1bbf Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 16 May 2026 11:28:25 -0500 Subject: fix(config-utilities): guard emacsql-close against nil sqlite handle EmacSQL 4.3.1 registers a finalizer per connection that calls emacsql-close after GC. The sqlite-builtin and sqlite-module backends clear their handle slot during an explicit close, so the finalizer later runs emacsql-close on a closed connection and sqlite-close fires: finalizer failed: (wrong-type-argument sqlitep nil) Adds an :around method on emacsql-close for both backends that short-circuits when the handle is already nil. Requires cl-generic and eieio at the top of the file so the cl-defmethod forms expand. --- modules/config-utilities.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/config-utilities.el b/modules/config-utilities.el index 8d094fda..4ed086d1 100644 --- a/modules/config-utilities.el +++ b/modules/config-utilities.el @@ -7,6 +7,8 @@ ;;; Code: (require 'cl-lib) +(require 'cl-generic) +(require 'eieio) (require 'find-lisp) (require 'profiler) @@ -45,6 +47,24 @@ (keymap-set cj/debug-config-keymap "t" #'toggle-debug-on-error) +;;; ----------------------------- Package Workarounds -------------------------- + +;; EmacSQL 4.3.1 registers finalizers that call `emacsql-close'. The sqlite +;; backends set their handle slot to nil after an explicit close, so a later +;; finalizer can otherwise call `sqlite-close' with nil and log: +;; finalizer failed: (wrong-type-argument sqlitep nil) +(with-eval-after-load 'emacsql-sqlite-builtin + (cl-defmethod emacsql-close :around + ((connection emacsql-sqlite-builtin-connection)) + (when (oref connection handle) + (cl-call-next-method)))) + +(with-eval-after-load 'emacsql-sqlite-module + (cl-defmethod emacsql-close :around + ((connection emacsql-sqlite-module-connection)) + (when (oref connection handle) + (cl-call-next-method)))) + ;;; -------------------------------- Benchmarking ------------------------------- (defmacro with-timer (title &rest forms) -- cgit v1.2.3