emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/emacsql 9f6c10eca0 172/427: Move error checking out to hel


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql 9f6c10eca0 172/427: Move error checking out to helper mix-in.
Date: Tue, 13 Dec 2022 02:59:39 -0500 (EST)

branch: elpa/emacsql
commit 9f6c10eca05fc46f3fb7af8c4a2761b4152e5fad
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>

    Move error checking out to helper mix-in.
---
 emacsql-psql.el   | 24 +++++-------------------
 emacsql-sqlite.el | 19 +++++--------------
 emacsql.el        |  8 ++++++++
 3 files changed, 18 insertions(+), 33 deletions(-)

diff --git a/emacsql-psql.el b/emacsql-psql.el
index 56583f6de4..5e076b40cc 100644
--- a/emacsql-psql.el
+++ b/emacsql-psql.el
@@ -68,30 +68,16 @@
     (when (process-live-p process)
       (process-send-string process "\\q\n"))))
 
-(defmethod emacsql-waiting-p ((connection emacsql-psql-connection))
-  (with-current-buffer (emacsql-buffer connection)
-    (cond ((= (buffer-size) 1) (string= "]" (buffer-string)))
-          ((> (buffer-size) 1) (string= "\n]"
-                                        (buffer-substring
-                                         (- (point-max) 2) (point-max)))))))
-
-(defun emacsql-psql--check-error (connection)
-  "Return non-nil or throw an appropriate error."
-  (with-current-buffer (emacsql-buffer connection)
-    (emacsql-wait connection)
-    (setf (point) (point-min))
-    (prog1 t
-      (when (looking-at "ERROR:")
-        (let ((message (buffer-substring (line-beginning-position)
-                                          (line-end-position))))
-          (emacsql-error "%s" message))))))
-
 (defmethod emacsql ((connection emacsql-psql-connection) sql &rest args)
   (let ((sql-string (apply #'emacsql-compile sql args)))
     (emacsql-clear connection)
     (emacsql-send-string connection sql-string)
     (emacsql-psql--check-error connection)
-    (emacsql-simple-parse connection)))
+    (emacsql-wait connection)
+    (let ((error (emacsql-simple-error-check connection)))
+      (if error
+          (signal 'emacsql-error (list error))
+        (emacsql-simple-parse connection)))))
 
 (provide 'emacsql-psql)
 
diff --git a/emacsql-sqlite.el b/emacsql-sqlite.el
index 4708ffbaf2..51019e5c1d 100644
--- a/emacsql-sqlite.el
+++ b/emacsql-sqlite.el
@@ -121,24 +121,15 @@ buffer. This is for debugging purposes."
                       :test (lambda (a b) (string-match-p b a))))
       'emacsql-error))
 
-(defun emacsql-sqlite--check-error (conn)
-  "Return non-nil or throw an appropriate error."
-  (with-current-buffer (emacsql-buffer conn)
-    (emacsql-wait conn)
-    (setf (point) (point-min))
-    (prog1 t
-      (when (looking-at "Error:")
-        (let* ((message (buffer-substring (line-beginning-position)
-                                          (line-end-position)))
-               (condition (emacsql-sqlite-get-condition message)))
-          (signal condition (list message)))))))
-
 (defmethod emacsql ((connection emacsql-sqlite-connection) sql &rest args)
   (let ((sql-string (apply #'emacsql-compile sql args)))
     (emacsql-clear connection)
     (emacsql-send-string connection sql-string)
-    (emacsql-sqlite--check-error connection)
-    (emacsql-simple-parse connection)))
+    (emacsql-wait connection)
+    (let ((error (emacsql-simple-error-check connection)))
+      (if error
+          (signal (emacsql-sqlite-get-condition error) (list error))
+        (emacsql-simple-parse connection)))))
 
 (provide 'emacsql-sqlite)
 
diff --git a/emacsql.el b/emacsql.el
index 17a574d56d..e3f6f2067c 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -169,6 +169,14 @@ Output should have one row per line, separated by 
whitespace."
                and do (progn (forward-char 1) (setf row ()))
                finally (cl-return rows)))))
 
+(defmethod emacsql-simple-error-check ((connection emacsql-simple-parser))
+  "Return the error message from CONNECTION, or nil for no error."
+  (with-current-buffer (emacsql-buffer connection)
+    (let ((case-fold-search t))
+      (setf (point) (point-min))
+      (when (looking-at "error:")
+        (buffer-substring (line-beginning-position) (line-end-position))))))
+
 (provide 'emacsql) ; end of generic function declarations
 
 ;; Automatic connection cleanup:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]