aboutsummaryrefslogtreecommitdiff
path: root/src/util.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-07-05 16:29:46 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-07-10 20:45:21 -0700
commit56bc5a2c24b0fe56c72ced9a5ac85d982d592567 (patch)
treed01d1820afeadd4d50794e45007bba9d9533b373 /src/util.lisp
parentec508517bc89d3934afa9ec91f3787839b14be2d (diff)
downloadconsfigurator-56bc5a2c24b0fe56c72ced9a5ac85d982d592567.tar.gz
signal SKIPPED-PROPERTIES & factor out interpreting exit codes
Unconditionally signalling FAILED-CHANGE does not make sense because perhaps the type of condition C is not a subtype of SIMPLE-CONDITION. Moreover, when we invoke the SKIP-PROPERTY restart we do not actually pass the condition. For simplicity, and since all we need is notification that a SKIP-PROPERTY restart was invoked, instead define and signal a special-purpose condition. Additionally, use an exit code to pass the signal between Lisp images. Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/util.lisp')
-rw-r--r--src/util.lisp55
1 files changed, 48 insertions, 7 deletions
diff --git a/src/util.lisp b/src/util.lisp
index 24ec85e..7dadfe9 100644
--- a/src/util.lisp
+++ b/src/util.lisp
@@ -453,13 +453,54 @@ of this macro."
Should be called soon after fork(2) in child processes."
(signal 'in-child-process))
-(defmacro with-backtrace-and-exit-code-two (&body forms)
- `(handler-bind
- ((serious-condition
- (lambda (c)
- (trivial-backtrace:print-backtrace c :output *error-output*)
- (uiop:quit 2))))
- ,@forms))
+(define-condition skipped-properties () ()
+ (:documentation
+ "There were failed changes, but instead of aborting, that particular property
+application was instead skipped over, either due to the semantics of a
+property combinator, or because the user elected to skip the property in the
+interactive debugger."))
+
+(defmacro with-deployment-report (&rest forms)
+ (with-gensyms (failures)
+ `(let* (,failures
+ (result (handler-bind ((skipped-properties (lambda (c)
+ (declare (ignore c))
+ (setq ,failures t))))
+ ,@forms)))
+ (inform
+ t
+ (cond
+ ((eql :no-change result)
+ "No changes were made.")
+ (,failures
+ "There were failures while attempting to apply some properties.")
+ (t
+ "Changes were made without any reported failures."))))))
+
+(defmacro with-backtrace-and-exit-code (&body forms)
+ (with-gensyms (failures)
+ `(let* (,failures
+ (result (handler-bind ((serious-condition
+ (lambda (c)
+ (trivial-backtrace:print-backtrace
+ c :output *error-output*)
+ (uiop:quit 3)))
+ (skipped-properties (lambda (c)
+ (declare (ignore c))
+ (setq ,failures t))))
+ ,@forms)))
+ (uiop:quit (cond ((eql :no-change result) 0)
+ (,failures 2)
+ (t 1))))))
+
+(defmacro return-exit (exit &key on-failure)
+ `(values
+ nil
+ (case ,exit
+ (0 :no-change)
+ (1 nil)
+ (2 (signal 'skipped-properties) nil)
+ (t ,on-failure))))
(defun posix-login-environment (logname home)
"Reset the environment after switching UID, or similar, in a :LISP connection.