[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 01/07: herd: Report errors according to the GNU standards.
From: |
Ludovic Courtès |
Subject: |
[shepherd] 01/07: herd: Report errors according to the GNU standards. |
Date: |
Fri, 22 Jan 2016 23:36:58 +0000 |
civodul pushed a commit to branch master
in repository shepherd.
commit 68724e24f648b5a931f685767fb2c56f564e1600
Author: Ludovic Courtès <address@hidden>
Date: Fri Jan 22 22:35:06 2016 +0100
herd: Report errors according to the GNU standards.
* modules/herd.scm (service-list-error): Remove.
(report-error): New macro.
(run-command): Use it instead of 'format'.
---
modules/herd.scm | 48 +++++++++++++++++++++++++-----------------------
1 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/modules/herd.scm b/modules/herd.scm
index 40bd10a..574dbb9 100644
--- a/modules/herd.scm
+++ b/modules/herd.scm
@@ -31,12 +31,19 @@
(define program-name "herd")
-
-(define (service-list-error services)
- (format (current-error-port)
- (l10n "~a: error: received an invalid service list:~%~s~%")
- program-name services))
+(define-syntax report-error
+ (lambda (s)
+ "Report an error to stderr."
+ (syntax-case s ()
+ ((_ (p message) args ...)
+ (string? (syntax->datum #'message))
+
+ (with-syntax ((message (string-append
+ "~a: " (syntax->datum #'message) "~%")))
+ #'(format (current-error-port) message
+ program-name args ...))))))
+
(define-syntax alist-let*
(syntax-rules ()
"Bind the given KEYs in EXP to the corresponding items in ALIST. ALIST
@@ -132,9 +139,8 @@ the daemon via SOCKET-FILE."
(for-each display-service-status result))
(('start _)
(unless result
- (format (current-error-port)
- (l10n "Failed to start service ~a~%")
- service)
+ (report-error (l10n "failed to start service ~a")
+ service)
(exit 1)))
(_
;; For other commands, we don't do any interpretation.
@@ -145,31 +151,27 @@ the daemon via SOCKET-FILE."
(for-each println messages)
(match error
(('error ('version 0 _ ...) 'service-not-found service)
- (format (current-error-port)
- (l10n "Service ~a could not be found.~%")
- service))
+ (report-error (l10n "service ~a could not be found")
+ service))
(('error ('version 0 _ ...) 'action-not-found action service)
- (format (current-error-port)
- (l10n "Service ~a does not have an action ~a.~%")
- service action))
+ (report-error (l10n "service ~a does not have an action ~a")
+ service action))
(('error ('version 0 _ ...) 'action-exception action service
key (args ...))
- (format (current-error-port)
- (l10n "Exception caught while executing '~a' \
-on service '~a':~%")
- action service)
+ (report-error (l10n "exception caught while executing '~a' \
+on service '~a':")
+ action service)
(print-exception (current-error-port) #f key args))
(('error . _)
- (format (current-error-port)
- (l10n "Something went wrong: ~s~%")
- error)))
+ (report-error (l10n "something went wrong: ~s")
+ error)))
(exit 1))
((? eof-object?)
;; When stopping shepherd, we may get an EOF in lieu of a real reply,
;; and that's fine. In other cases, a premature EOF is an error.
(unless (and (eq? action 'stop) (eq? service 'dmd))
- (format (current-error-port)
- (l10n "premature end-of-file while talking to shepherd~%"))
+ (report-error (l10n "premature end-of-file while \
+talking to shepherd"))
(exit 1))))
(close-port sock))))
- [shepherd] branch master updated (852341e -> 28ed7e1), Ludovic Courtès, 2016/01/22
- [shepherd] 01/07: herd: Report errors according to the GNU standards.,
Ludovic Courtès <=
- [shepherd] 03/07: support: Add 'display-line'., Ludovic Courtès, 2016/01/22
- [shepherd] 04/07: comm: Add 'report-command-error'., Ludovic Courtès, 2016/01/22
- [shepherd] 05/07: reboot, halt: Adjust to sexp replies., Ludovic Courtès, 2016/01/22
- [shepherd] 07/07: Rename 'dmd-output-port' to 'shepherd-output-port'., Ludovic Courtès, 2016/01/22
- [shepherd] 02/07: Move 'report-error' to (shepherd support)., Ludovic Courtès, 2016/01/22
- [shepherd] 06/07: shepherd: Ignore SIGPIPE., Ludovic Courtès, 2016/01/22