Commit fca62384 authored by Simen Heggestøyl's avatar Simen Heggestøyl
Browse files

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.
parent 25a49f64
......@@ -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)))
(dolist (row (process-lines sql-postgres-program "-ltX"))
(when (string-match "^ \\([[:alnum:]-_]+\\) +|.*" row)
(push (match-string 1 row) res))))
(nreverse res))))
;; Customization for Interbase
......@@ -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."
(((symbol-function 'executable-find)
(lambda (_command) t))
((symbol-function 'process-lines)
(lambda (_program &rest _args)
(should-not (sql-postgres-list-databases))))
(provide 'sql-tests)
;;; sql-tests.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment