emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/pq 45a732a4c2 31/63: Add test for signal error


From: ELPA Syncer
Subject: [elpa] externals/pq 45a732a4c2 31/63: Add test for signal error
Date: Mon, 14 Feb 2022 23:24:23 -0500 (EST)

branch: externals/pq
commit 45a732a4c26c5a04a407c3e6476d76b9a8bb8ea9
Author: Mario Rodas <marsam@users.noreply.github.com>
Commit: Mario Rodas <marsam@users.noreply.github.com>

    Add test for signal error
    
    Signal "error" instead of "pg:error" to avoid defining our custom error 
signals
---
 pq.c    | 12 ++++++------
 test.el |  3 +++
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/pq.c b/pq.c
index 2f1b5d4839..8fb7726377 100644
--- a/pq.c
+++ b/pq.c
@@ -17,7 +17,7 @@ static emacs_value Qt;
 
 static void pq_notice_rx (void *arg, const PGresult *res)
 {
-     char *msg = PQresultErrorMessage(res);
+     const char *msg = PQresultErrorMessage(res);
      emacs_env *env = arg;
      emacs_value Fmessage = env->intern (env, "message");
      size_t len = strlen(msg);
@@ -50,9 +50,9 @@ static bool result_ok(emacs_env *env, PGresult *res)
   case PGRES_FATAL_ERROR:
   default:
     {
-      char *errmsg = PQresultErrorMessage(res);
+      const char *errmsg = PQresultErrorMessage(res);
       emacs_value errstring = env->make_string(env, errmsg, strlen(errmsg));
-      emacs_value Qpq_error = env->intern (env, "pq:error");
+      emacs_value Qpq_error = env->intern (env, "error");
 
       PQclear(res);
       env->non_local_exit_signal(env, Qpq_error, errstring);
@@ -87,10 +87,10 @@ Fpq_connectdb (emacs_env *env, ptrdiff_t nargs, emacs_value 
args[], void *data)
   char *conninfo = nargs ? my_string_to_c(env, args[0]) : "";
   PGconn *conn = PQconnectdb(conninfo);
 
-  char *errmsg = PQerrorMessage(conn);
-  if (strlen(errmsg)) {
+  if (PQstatus(conn) != CONNECTION_OK) {
+    const char *errmsg = PQerrorMessage(conn);
     emacs_value errstring = env->make_string(env, errmsg, strlen(errmsg));
-    emacs_value Qpq_error = env->intern (env, "pq:error");
+    emacs_value Qpq_error = env->intern (env, "error");
 
     env->non_local_exit_signal(env, Qpq_error, errstring);
     if (nargs)
diff --git a/test.el b/test.el
index 3eafc21736..1c8f8561bb 100644
--- a/test.el
+++ b/test.el
@@ -27,3 +27,6 @@
   (let ((conn (pq:connectdb *conninfo*)))
     (should (equal (pq:escapeLiteral conn "mo'oo\"oo") "'mo''oo\"oo'"))
     (should (equal (pq:escapeIdentifier conn "moo'oo\"oo") 
"\"moo'oo\"\"oo\""))))
+
+(ert-deftest pq-signal-error-test ()
+  (should-error (pq:connectdb "invalid-conninfo")))



reply via email to

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