Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Dec 14, 2023
1 parent e8e1853 commit d73dd8f
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions emacsql-sqlite.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit d73dd8f

Please sign in to comment.