diff --git a/emacsql-sqlite.el b/emacsql-sqlite.el index fc02d42..ec514f6 100644 --- a/emacsql-sqlite.el +++ b/emacsql-sqlite.el @@ -59,21 +59,6 @@ used.") (emacsql--sqlite-base emacsql-protocol-mixin) () "A connection to a SQLite database.") -(defun emacsql-sqlite--sentinel (process _) - "If PROCESS is not alive kill its associated buffer. -Signal an error if PROCESS exited abnormally." - (unless (process-live-p process) - (let* ((buffer (process-buffer process)) - (contents (and (buffer-live-p buffer) - (with-current-buffer buffer (buffer-string)))) - (status (process-exit-status process))) - (kill-buffer buffer) - (when (> status 0) - (error "%s exited abnormallly :status %S :exit-code %d :last-output %s" - emacsql-sqlite-executable - (process-status process) - status contents))))) - (cl-defmethod initialize-instance :after ((connection emacsql-sqlite-connection) &rest _rest) (emacsql-sqlite-ensure-binary) @@ -87,7 +72,16 @@ Signal an error if PROCESS exited abnormally." (process (start-process "emacsql-sqlite" buffer emacsql-sqlite-executable fullfile))) (oset connection handle process) - (set-process-sentinel process #'emacsql-sqlite--sentinel) + (set-process-sentinel + process + (lambda (process _) + (cond ((process-live-p process)) + ((zerop (process-exit-status process)) + (kill-buffer buffer)) + ((let ((errmsg (and (buffer-live-p buffer) + (with-current-buffer buffer (buffer-string))))) + (kill-buffer buffer) + (signal 'emacsql-error errmsg)))))) (when (memq (process-status process) '(exit signal)) (error "%s has failed immediately" emacsql-sqlite-executable)) (emacsql-wait connection)