all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Simen Heggestøyl" <simenheg@gmail.com>
To: Michael Mauger <michael@mauger.com>
Cc: "sunshavi@fastmail.fm" <sunshavi@fastmail.fm>,
	"25236@debbugs.gnu.org" <25236@debbugs.gnu.org>
Subject: bug#25236: 26.0.50; sql-postgres not working on master
Date: Sat, 18 Feb 2017 18:01:55 +0100	[thread overview]
Message-ID: <1487437315.31870.0@smtp.gmail.com> (raw)
In-Reply-To: <1397003198.5767161.1483499760212@mail.yahoo.com>

[-- Attachment #1: Type: text/plain, Size: 498 bytes --]

On Wed, Jan 4, 2017 at 4:16 AM, Michael Mauger <michael@mauger.com> 
wrote:
> Just got back after the holiday. Makes sense that could be a problem. 
> I'm getting ready to push a change related to completing-read so let 
> me take a look.
> 
> Thanks for staying on top of this...

I think the attached patch fixes half of the problem. Then we need to
do something about the `completing-read' to make it possible to still
select a database when `sql-postgres-list-databases' returns nil.

-- Simen

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Handle-non-zero-exit-status-from-psql-more-gracefull.patch --]
[-- Type: text/x-patch, Size: 2119 bytes --]

From 100fc2038511a10edbda1fbf0c877bef33efbe4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg@gmail.com>
Date: Sat, 18 Feb 2017 17:50:16 +0100
Subject: [PATCH] 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 8868343129..4a936a6b45 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -1087,9 +1087,10 @@ sql-postgres-list-databases
   "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 27a72aa2c2..f75005f737 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
-- 
2.11.0


  reply	other threads:[~2017-02-18 17:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-20  3:30 bug#25236: 26.0.50; sql-postgres not working on master sunshavi
2016-12-30 18:17 ` Simen Heggestøyl
2017-01-04  3:16   ` Michael Mauger
2017-02-18 17:01     ` Simen Heggestøyl [this message]
2017-05-04 19:57       ` erreina
2017-07-29 16:26     ` Simen Heggestøyl
2017-07-29 17:15       ` bug#25236: new mail address (was: bug#25236: 26.0.50; sql-postgres not working on master) andrés ramírez
2017-08-07  1:01       ` bug#25236: 26.0.50; sql-postgres not working on master Michael Mauger
     [not found]         ` <a5m7xFNQkeRpgX_47Xz0JyMFjnO9mnKQXGyJcUcNrsv4THBUs3MB-WRw95G3uMKydbmO6iqKmCjp Nw-fgmo4vg==@protonmail.com>
2017-08-10 21:26           ` Simen Heggestøyl
2017-09-02 13:09             ` Eli Zaretskii
2017-09-05  0:18               ` Michael Mauger
     [not found]                 ` <Q9cdamlTWxEGS1Mjo7CPiTh35FxxlG4lWUukF0rR8xem_cIYrZKxQNoZtk0gBkPL393mVJg0kbSA 1hMZFvOoTQ==@protonmail.com>
2017-09-05 18:36                   ` Simen Heggestøyl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1487437315.31870.0@smtp.gmail.com \
    --to=simenheg@gmail.com \
    --cc=25236@debbugs.gnu.org \
    --cc=michael@mauger.com \
    --cc=sunshavi@fastmail.fm \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.