diff mbox series

[bug#70494,16/23] store: database: Log when aborting transactions.

Message ID 21c24e8933feb110c2e6cd5782d39adab3b66546.1713692561.git.mail@cbaines.net
State New
Headers show
Series Groundwork for the Guile guix-daemon | expand

Commit Message

Christopher Baines April 21, 2024, 9:42 a.m. UTC
Otherwise this has the effect of masking the backtrace/exception.

* guix/store/database.scm (call-with-transaction): Log when aborting.

Change-Id: Iee31905c4688dc62ef37a85b0208fd324ee67d70
---
 guix/store/database.scm | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/guix/store/database.scm b/guix/store/database.scm
index 8a3436368e..b6f87d710f 100644
--- a/guix/store/database.scm
+++ b/guix/store/database.scm
@@ -154,9 +154,17 @@  (define* (call-with-transaction db proc #:key restartable?)
   (sqlite-exec db (if restartable? "begin;" "begin immediate;"))
   (catch #t
     (lambda ()
-      (let-values ((result (proc)))
-        (sqlite-exec db "commit;")
-        (apply values result)))
+      (with-throw-handler #t
+        (lambda ()
+          (call-with-values proc
+            (lambda vals
+              (sqlite-exec db "commit;")
+              (apply values vals))))
+        (lambda (key args)
+          (simple-format
+           (current-error-port)
+           "transaction aborted: ~A: ~A\n" key args)
+          (backtrace))))
     (lambda args
       ;; The roll back may or may not have occurred automatically when the
       ;; error was generated. If it has occurred, this does nothing but signal