emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master fca6238: Handle non-zero exit status from psql more


From: Simen Heggestøyl
Subject: [Emacs-diffs] master fca6238: Handle non-zero exit status from psql more gracefully
Date: Tue, 5 Sep 2017 14:32:07 -0400 (EDT)

branch: master
commit fca62384537e1a32e867f4d3181e0b2b79396383
Author: Simen Heggestøyl <address@hidden>
Commit: Simen Heggestøyl <address@hidden>

    Handle non-zero exit status from psql more gracefully
    
    * lisp/progmodes/sql.el (sql-postgres-list-databases): Handle non-zero
    exit statuses from `psql -ltX' more gracefully by returning nil.
    
    * test/lisp/progmodes/sql-tests.el
    (sql-tests-postgres-list-databases-error): New test.
---
 lisp/progmodes/sql.el            |  7 ++++---
 test/lisp/progmodes/sql-tests.el | 10 ++++++++++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index b176e52..48e2160 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -1095,9 +1095,10 @@ add your name with a \"-U\" prefix (such as \"-Umark\") 
to the list."
   "Return a list of available PostgreSQL databases."
   (when (executable-find sql-postgres-program)
     (let ((res '()))
-      (dolist (row (process-lines sql-postgres-program "-ltX"))
-        (when (string-match "^ \\([[:alnum:]-_]+\\) +|.*" row)
-          (push (match-string 1 row) res)))
+      (ignore-errors
+        (dolist (row (process-lines sql-postgres-program "-ltX"))
+          (when (string-match "^ \\([[:alnum:]-_]+\\) +|.*" row)
+            (push (match-string 1 row) res))))
       (nreverse res))))
 
 ;; Customization for Interbase
diff --git a/test/lisp/progmodes/sql-tests.el b/test/lisp/progmodes/sql-tests.el
index 27a72aa..f75005f 100644
--- a/test/lisp/progmodes/sql-tests.el
+++ b/test/lisp/progmodes/sql-tests.el
@@ -43,5 +43,15 @@
     (should (equal (sql-postgres-list-databases)
                    '("db-name-1" "db_name_2")))))
 
+(ert-deftest sql-tests-postgres-list-databases-error ()
+  "Test that nil is returned when `psql -ltX' fails."
+  (cl-letf
+      (((symbol-function 'executable-find)
+        (lambda (_command) t))
+       ((symbol-function 'process-lines)
+        (lambda (_program &rest _args)
+          (error))))
+    (should-not (sql-postgres-list-databases))))
+
 (provide 'sql-tests)
 ;;; sql-tests.el ends here



reply via email to

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