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) #t)
#f)) #f))
(define (handler request body controller secret-key-base startup-completed (define (handler request finished?
body controller secret-key-base startup-completed
render-metrics) 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 (display
(format #f "~a ~a\n" (format #f "~a ~a\n"
(request-method request) (request-method request)
(uri-path (request-uri request)))) (uri-path (request-uri request)))))
#:unwind? #t)
(apply values (apply values
(let-values (((request-components mime-types) (let-values (((request-components mime-types)
(request->path-components-and-mime-type request))) (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 () (lambda ()
(run-server/patched (run-server/patched
(lambda (request body) (lambda (request body)
(handler request body controller (handler request finished? body controller
secret-key-base secret-key-base
startup-completed startup-completed
render-metrics)) render-metrics))