From 8e2c6db1ffb73f7e26044cc054730fffa9a90c24 Mon Sep 17 00:00:00 2001
From: "Stephen R. van den Berg" <srb@cuci.nl>
Date: Tue, 13 Apr 2021 14:25:36 +0200
Subject: [PATCH] pgsql: Attempt at preventing exceptions during backtrace
 display.

---
 lib/modules/Sql.pmod/pgsql_util.pmod | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lib/modules/Sql.pmod/pgsql_util.pmod b/lib/modules/Sql.pmod/pgsql_util.pmod
index 26fb366abe..99fd4622fe 100644
--- a/lib/modules/Sql.pmod/pgsql_util.pmod
+++ b/lib/modules/Sql.pmod/pgsql_util.pmod
@@ -2714,12 +2714,14 @@ class proxy {
        * inside a destructor, throwing an error will not work anymore.
        * Warnings will be silently discarded at this point.
        */
-      lastmessage = filter(lastmessage, lambda(string val) {
-        return has_prefix(val, "ERROR ") || has_prefix(val, "FATAL "); });
-      if (err || (err = catch(errstring = geterror(1))))
-        werror(describe_backtrace(err));
-      else if (errstring && sizeof(errstring))
-        werror("%s\n", errstring);	// Add missing terminating newline
+      catch {	// Use yet another catch for exceptions in backtraces
+        lastmessage = filter(lastmessage, lambda(string val) {
+          return has_prefix(val, "ERROR ") || has_prefix(val, "FATAL "); });
+        if (err || (err = catch(errstring = geterror(1))))
+          werror(describe_backtrace(err));
+        else if (errstring && sizeof(errstring))
+          werror("%s\n", errstring);	// Add missing terminating newline
+      };
     }
   }
 
-- 
GitLab