From 6c8395e57de95f5972e55e106338aa241ec7a15e Mon Sep 17 00:00:00 2001 From: Bart Botta <00003b@gmail.com> Date: Wed, 23 Sep 2020 16:15:14 -0500 Subject: [PATCH] ignore errors while printing error and backtrace, so we still exit properly --- src/utils.lisp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/utils.lisp b/src/utils.lisp index 2b06652..771710d 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -4,13 +4,19 @@ (in-package :ci-utils/utils) + (defmacro with-fail-on-errors ((&key (code 123)) &body body) "print a stack trace and then exit with CODE when BODY signals any error" `(handler-bind ((error (lambda (&optional e) - (format t "caught error ~s~%~a~%" e e) - (uiop:print-condition-backtrace - e :stream *standard-output*) + (format t "caught error:~%") + ;; make sure we exit properly even if + ;; errors or backtrace can't be printed + (ignore-errors (format t " ~a~%" e)) + (ignore-errors (format t " ~s~%" e)) + (ignore-errors + (uiop:print-condition-backtrace + e :stream *standard-output*)) (finish-output) (uiop:quit ,code)))) (progn ,@body)))