civodul pushed a commit to branch devel
in repository shepherd.

commit 42d89407e7fd1740496b6f188a2078d30b87b642
Author: Ludovic Courtès <l...@gnu.org>
AuthorDate: Fri May 10 22:59:04 2024 +0200

    shepherd: Properly report ‘&message’ exceptions from config file.
    
    * modules/shepherd.scm (configuration-file-loader): Add
    ‘message-condition?’ clause and ‘else’ clause.
    * tests/services/timer.sh: Test error reporting for invalid
    ‘calendar-event’ arguments.
---
 modules/shepherd.scm    | 10 ++++++++++
 tests/services/timer.sh | 14 ++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index f7e302b..490cf65 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -186,6 +186,16 @@ using fallback mechanism."))
               ((exception-with-kind-and-args? c)
                (handle-key-and-args-exception
                 (exception-kind c) (exception-args c))
+               (failure))
+              ((message-condition? c)
+               (local-output
+                (l10n "Error while loading configuration file '~a': ~a")
+                file (condition-message c))
+               (failure))
+              (else
+               (local-output (l10n "Uncaught exception while loading \
+configuration file '~a': ~s")
+                             file c)
                (failure)))
       (load-in-user-module file)
       (local-output (l10n "Configuration successfully loaded from '~a'.")
diff --git a/tests/services/timer.sh b/tests/services/timer.sh
index 2158a43..09f9011 100644
--- a/tests/services/timer.sh
+++ b/tests/services/timer.sh
@@ -120,3 +120,17 @@ $herd trigger never-timer
 until grep "Triggered from $PWD" "$log"; do sleep 0.3; done
 
 $herd stop root
+
+while kill -0 "$(cat $pid)" ; do sleep 0.2; done
+
+# Check error reports when config is invalid.
+cat > "$conf" <<EOF
+(use-modules (shepherd service timer))
+
+(calendar-event #:days-of-week '(1 2 3))  ;wrong!
+EOF
+rm -f "$pid"
+shepherd -I -s "$socket" -c "$conf" -l "$log" --pid="$pid" &
+until grep "invalid day of week" "$log"; do sleep 0.2; done
+
+$herd stop root

Reply via email to