diff options
| author | Simen Heggestøyl | 2017-08-09 15:34:34 +0200 |
|---|---|---|
| committer | Simen Heggestøyl | 2017-09-05 20:31:21 +0200 |
| commit | fca62384537e1a32e867f4d3181e0b2b79396383 (patch) | |
| tree | c6586fb7df23770b3f2f7763a9d3337c05653285 | |
| parent | 25a49f64963d1c2a392ebaa66676042b55e0e3c1 (diff) | |
| download | emacs-fca62384537e1a32e867f4d3181e0b2b79396383.tar.gz emacs-fca62384537e1a32e867f4d3181e0b2b79396383.zip | |
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.
| -rw-r--r-- | lisp/progmodes/sql.el | 7 | ||||
| -rw-r--r-- | 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 b176e52950c..48e21605a33 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." | |||
| 1095 | "Return a list of available PostgreSQL databases." | 1095 | "Return a list of available PostgreSQL databases." |
| 1096 | (when (executable-find sql-postgres-program) | 1096 | (when (executable-find sql-postgres-program) |
| 1097 | (let ((res '())) | 1097 | (let ((res '())) |
| 1098 | (dolist (row (process-lines sql-postgres-program "-ltX")) | 1098 | (ignore-errors |
| 1099 | (when (string-match "^ \\([[:alnum:]-_]+\\) +|.*" row) | 1099 | (dolist (row (process-lines sql-postgres-program "-ltX")) |
| 1100 | (push (match-string 1 row) res))) | 1100 | (when (string-match "^ \\([[:alnum:]-_]+\\) +|.*" row) |
| 1101 | (push (match-string 1 row) res)))) | ||
| 1101 | (nreverse res)))) | 1102 | (nreverse res)))) |
| 1102 | 1103 | ||
| 1103 | ;; Customization for Interbase | 1104 | ;; Customization for Interbase |
diff --git a/test/lisp/progmodes/sql-tests.el b/test/lisp/progmodes/sql-tests.el index 27a72aa2c23..f75005f737f 100644 --- a/test/lisp/progmodes/sql-tests.el +++ b/test/lisp/progmodes/sql-tests.el | |||
| @@ -43,5 +43,15 @@ | |||
| 43 | (should (equal (sql-postgres-list-databases) | 43 | (should (equal (sql-postgres-list-databases) |
| 44 | '("db-name-1" "db_name_2"))))) | 44 | '("db-name-1" "db_name_2"))))) |
| 45 | 45 | ||
| 46 | (ert-deftest sql-tests-postgres-list-databases-error () | ||
| 47 | "Test that nil is returned when `psql -ltX' fails." | ||
| 48 | (cl-letf | ||
| 49 | (((symbol-function 'executable-find) | ||
| 50 | (lambda (_command) t)) | ||
| 51 | ((symbol-function 'process-lines) | ||
| 52 | (lambda (_program &rest _args) | ||
| 53 | (error)))) | ||
| 54 | (should-not (sql-postgres-list-databases)))) | ||
| 55 | |||
| 46 | (provide 'sql-tests) | 56 | (provide 'sql-tests) |
| 47 | ;;; sql-tests.el ends here | 57 | ;;; sql-tests.el ends here |