guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[shepherd] 04/07: comm: Add 'report-command-error'.


From: Ludovic Courtès
Subject: [shepherd] 04/07: comm: Add 'report-command-error'.
Date: Fri, 22 Jan 2016 23:36:59 +0000

civodul pushed a commit to branch master
in repository shepherd.

commit 002618342cd92323afe0f57b412de30608b4a785
Author: Ludovic Courtès <address@hidden>
Date:   Fri Jan 22 23:33:08 2016 +0100

    comm: Add 'report-command-error'.
    
    * modules/herd.scm (run-command): Move error interpretation to...
    * modules/shepherd/comm.scm (report-command-error): ... here.  New
    procedure.
---
 modules/herd.scm          |   17 +----------------
 modules/shepherd/comm.scm |   23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/modules/herd.scm b/modules/herd.scm
index c7b6449..bc6c578 100644
--- a/modules/herd.scm
+++ b/modules/herd.scm
@@ -130,22 +130,7 @@ the daemon via SOCKET-FILE."
                 ('result _) ('error error)
                 ('messages messages))
         (for-each display-line messages)
-        (match error
-          (('error ('version 0 _ ...) 'service-not-found service)
-           (report-error (l10n "service ~a could not be found")
-                         service))
-          (('error ('version 0 _ ...) 'action-not-found action service)
-           (report-error (l10n "service ~a does not have an action ~a")
-                         service action))
-          (('error ('version 0 _ ...) 'action-exception action service
-                   key (args ...))
-           (report-error (l10n "exception caught while executing '~a' \
-on service '~a':")
-                         action service)
-           (print-exception (current-error-port) #f key args))
-          (('error . _)
-           (report-error (l10n "something went wrong: ~s")
-                         error)))
+        (report-command-error error)
         (exit 1))
        ((? eof-object?)
         ;; When stopping shepherd, we may get an EOF in lieu of a real reply,
diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm
index 2402e7e..1c086fe 100644
--- a/modules/shepherd/comm.scm
+++ b/modules/shepherd/comm.scm
@@ -46,6 +46,7 @@
 
             write-reply
             result->sexp
+            report-command-error
 
             start-logging
             stop-logging
@@ -145,6 +146,28 @@ return the socket."
 (define-method (result->sexp (kw <keyword>)) kw)
 (define-method (result->sexp (obj <top>)) (object->string obj))
 
+(define (report-command-error error)
+  "Report ERROR, an sexp received by a shepherd client in reply to COMMAND, a
+command object."
+  (match error
+    (('error ('version 0 _ ...) 'service-not-found service)
+     (report-error (l10n "service '~a' could not be found")
+                   service))
+    (('error ('version 0 _ ...) 'action-not-found action service)
+     (report-error (l10n "service '~a' does not have an action ~a")
+                   service action))
+    (('error ('version 0 _ ...) 'action-exception action service
+             key (args ...))
+     (report-error (l10n "exception caught while executing '~a' \
+on service '~a':")
+                   action service)
+     (print-exception (current-error-port) #f key args))
+    (('error . _)
+     (report-error (l10n "something went wrong: ~s")
+                   error))
+    (#f                                           ;not an error
+     #t)))
+
 
 
 ;; Port for logging.  This must always be a valid port, never `#f'.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]