Use with-exception-handler in place of with-throw-handler

This commit is contained in:
Christopher Baines 2025-02-25 10:38:10 +00:00
parent 1da2a09cfb
commit e591346684
7 changed files with 109 additions and 98 deletions

View file

@ -180,8 +180,11 @@
(define* (with-postgresql-connection name f #:key (statement-timeout #f))
(let ((conn (open-postgresql-connection name statement-timeout)))
(with-throw-handler
#t
(with-exception-handler
(lambda (exn)
(pg-conn-finish conn)
(decrement-connection-gauge name)
(raise-exception exn))
(lambda ()
(call-with-values
(lambda ()
@ -191,10 +194,7 @@
(decrement-connection-gauge name)
(apply values vals))))
(lambda (key . args)
(pg-conn-finish conn)
(decrement-connection-gauge name)))))
(apply values vals)))))))
(define %postgresql-connection-parameters
(make-parameter #f))
@ -209,15 +209,20 @@
#:key always-rollback?)
(exec-query conn "BEGIN;")
(with-throw-handler #t
(with-exception-handler
(lambda (exn)
(with-exception-handler
(const #f)
(lambda ()
(exec-query conn "ROLLBACK;"))
#:unwind? #t)
(raise-exception exn))
(lambda ()
(let ((result (f conn)))
(exec-query conn (if always-rollback?
"ROLLBACK;"
"COMMIT;"))
result))
(lambda (key . args)
(exec-query conn "ROLLBACK;"))))
result))))
(define (check-test-database! conn)
(match (exec-query conn "SELECT current_database()")
@ -247,17 +252,22 @@
(exec-query conn
"SELECT pg_advisory_lock($1)"
(list lock-number))
(with-throw-handler #t
(with-exception-handler
(lambda (exn)
(with-exception-handler
(const #f)
(lambda ()
(exec-query conn
"SELECT pg_advisory_unlock($1)"
(list lock-number)))
#:unwind? #t)
(raise-exception exn))
(lambda ()
(let ((result (f)))
(exec-query conn
"SELECT pg_advisory_unlock($1)"
(list lock-number))
result))
(lambda (key . args)
(exec-query conn
"SELECT pg_advisory_unlock($1)"
(list lock-number))))))
result)))))
(define (with-advisory-session-lock/log-time conn lock f)
(simple-format #t "debug: Acquiring advisory session lock: ~A\n" lock)

View file

@ -22,6 +22,7 @@
#:use-module (srfi srfi-71)
#:use-module (ice-9 threads)
#:use-module (squee)
#:use-module (knots)
#:use-module (git)
#:use-module (guix git)
#:use-module (guix channels)
@ -57,11 +58,12 @@
(simple-format #t "exception when polling git repository (~A): ~A\n"
git-repository-id exn))
(lambda ()
(with-throw-handler #t
(with-exception-handler
(lambda (exn)
(print-backtrace-and-exception/knots exn)
(raise-exception exn))
(lambda ()
(poll-git-repository conn git-repository-id))
(lambda _
(backtrace))))
(poll-git-repository conn git-repository-id))))
#:unwind? #t)
(and=>

View file

@ -27,6 +27,7 @@
#:use-module (guix narinfo)
#:use-module ((guix build syscalls)
#:select (set-thread-name))
#:use-module (knots)
#:use-module (guix-data-service utils)
#:use-module (guix-data-service database)
#:use-module (guix-data-service model build)
@ -56,17 +57,18 @@
(member id build-server-ids))
(when lookup-all-derivations?
(simple-format #t "\nQuerying ~A\n" url)
(with-throw-handler #t
(with-exception-handler
(lambda (exn)
(simple-format
(current-error-port)
"exception in query-build-server ~A ~A\n"
id url)
(print-backtrace-and-exception/knots exn)
(raise-exception exn))
(lambda ()
(fetch-narinfo-files conn id url revision-commits
#:specific-outputs
outputs))
(lambda (key . args)
(simple-format
(current-error-port)
"exception in query-build-server: ~A ~A\n"
key args)
(backtrace)))))))
outputs)))))))
build-servers))))
(define %narinfo-max-size
@ -169,12 +171,15 @@
(while #t
(with-exception-handler
(lambda (exn)
(simple-format
(current-error-port)
"exception in request substitute query thread: ~A\n"
exn))
#f)
(lambda ()
(with-throw-handler #t
(with-exception-handler
(lambda (exn)
(simple-format
(current-error-port)
"exception in request substitute query thread:\n")
(print-backtrace-and-exception/knots exn)
(raise-exception exn))
(lambda ()
(with-postgresql-connection
"request-substitute-query-thread"
@ -200,9 +205,7 @@
conn
(list build-server-id)
#f
outputs))))))))
(lambda _
(backtrace))))
outputs))))))))))
#:unwind? #t))))
(call-with-new-thread

View file

@ -22,6 +22,7 @@
#:use-module (json)
#:use-module (squee)
#:use-module (fibers)
#:use-module (knots)
#:use-module (knots resource-pool)
#:use-module (prometheus)
#:use-module (guix-data-service utils)
@ -134,12 +135,12 @@
"exception in build event handler: ~A\n"
exn))
(lambda ()
(with-throw-handler #t
(with-exception-handler
(lambda (exn)
(print-backtrace-and-exception/knots exn)
(raise-exception exn))
(lambda ()
(handler conn))
(lambda _
(display (backtrace) (current-error-port))
(display "\n" (current-error-port)))))
(handler conn))))
#:unwind? #t))
#:timeout #f))))