[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:
- [nongnu] elpa/emacsql 6c32f02139 137/427: Add emacsql-thread macro., (continued)
- [nongnu] elpa/emacsql 6c32f02139 137/427: Add emacsql-thread macro., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 54c180017e 138/427: Add :pragma and note in README., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 5e2ab842f7 139/427: Add foreign key test., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 42c2fd7569 145/427: Tweak limitation wording., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql fe0c7004fc 146/427: Add :begin, :commit, and :rollback., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 2550196816 162/427: Drop SQLite version requirements., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 9a1b4209ba 164/427: Add PostgreSQL front-end., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 5f4c2ed5a7 166/427: Add emacsql-psql-unavailable-p., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 1d0ef4011c 167/427: Make emacsql-connection abstract., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 64c3a03d62 169/427: Flesh out some more README., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 9f6c10eca0 172/427: Move error checking out to helper mix-in.,
ELPA Syncer <=
- [nongnu] elpa/emacsql 4f76b94f7c 168/427: Set psql to print nil for NULL., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 7434263d82 174/427: Oops, drop leftover function call., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql ca62adc4b2 177/427: Add debug argument to emacsql-psql., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql afef528d81 179/427: Fix memoization to include type map., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql b2f2dd37cf 178/427: Allow connection to specify their own types., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 4aa889882d 182/427: Fix slot allocation on emacsql-connection., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 769abe20fa 183/427: Don't rely on a closure in cleanup hook., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e9efb0803e 185/427: Oops, include the reap source., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 5962268f83 184/427: Split off reaper code., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql f8c3d9fce2 369/427: Silence Emacs 25's byte-compiler, ELPA Syncer, 2022/12/13