Guard against logging failing

As I've seen this happening where there are errors writing to FD 1.
This commit is contained in:
Christopher Baines 2024-04-02 12:04:23 +01:00
parent 15d436032a
commit 65f92ca701

View file

@ -49,12 +49,25 @@
#t)
#f))
(define (handler request body controller secret-key-base startup-completed
(define (handler request finished?
body controller secret-key-base startup-completed
render-metrics)
(with-exception-handler
(lambda (exn)
(with-exception-handler
(lambda _ #f)
(lambda ()
(simple-format (current-error-port)
"exception when logging: ~A\n" exn))
#:unwind? #t)
;; If we can't log, exit
(signal-condition! finished?))
(lambda ()
(display
(format #f "~a ~a\n"
(request-method request)
(uri-path (request-uri request))))
(uri-path (request-uri request)))))
#:unwind? #t)
(apply values
(let-values (((request-components mime-types)
(request->path-components-and-mime-type request)))
@ -152,7 +165,7 @@ port. Also, the port used can be changed by passing the --port option.\n"
(lambda ()
(run-server/patched
(lambda (request body)
(handler request body controller
(handler request finished? body controller
secret-key-base
startup-completed
render-metrics))