From: "Ludovic Courtès" <ludo@gnu.org>
To: 48685@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#48685] [PATCH 2/2] ui, lint: Simplify exception handling in Guile 3 style.
Date: Wed, 26 May 2021 23:18:14 +0200 [thread overview]
Message-ID: <20210526211814.17116-2-ludo@gnu.org> (raw)
In-Reply-To: <20210526211814.17116-1-ludo@gnu.org>
* guix/lint.scm (check-derivation)[try]: Remove "catch #t" wrapping.
* guix/ui.scm (call-with-error-handling): Remove "catch 'system-error"
and move 'system-error handling to the &exception-with-kind-and-args
clause.
---
guix/lint.scm | 70 +++++++++++++++++++++++----------------------------
guix/ui.scm | 14 +++++------
2 files changed, 39 insertions(+), 45 deletions(-)
diff --git a/guix/lint.scm b/guix/lint.scm
index 023a179ea6..41dd5d0633 100644
--- a/guix/lint.scm
+++ b/guix/lint.scm
@@ -1010,45 +1010,39 @@ descriptions maintained upstream."
(define* (check-derivation package #:key store)
"Emit a warning if we fail to compile PACKAGE to a derivation."
(define (try store system)
- (catch #t ;TODO: Remove 'catch' when Guile 2.x is no longer supported.
- (lambda ()
- (guard (c ((store-protocol-error? c)
- (make-warning package
- (G_ "failed to create ~a derivation: ~a")
- (list system
- (store-protocol-error-message c))))
- ((exception-with-kind-and-args? c)
- (make-warning package
- (G_ "failed to create ~a derivation: ~s")
- (list system
- (cons (exception-kind c)
- (exception-args c)))))
- ((message-condition? c)
- (make-warning package
- (G_ "failed to create ~a derivation: ~a")
- (list system
- (condition-message c))))
- ((formatted-message? c)
- (let ((str (apply format #f
- (formatted-message-string c)
- (formatted-message-arguments c))))
- (make-warning package
- (G_ "failed to create ~a derivation: ~a")
- (list system str)))))
- (parameterize ((%graft? #f))
- (package-derivation store package system #:graft? #f)
+ (guard (c ((store-protocol-error? c)
+ (make-warning package
+ (G_ "failed to create ~a derivation: ~a")
+ (list system
+ (store-protocol-error-message c))))
+ ((exception-with-kind-and-args? c)
+ (make-warning package
+ (G_ "failed to create ~a derivation: ~s")
+ (list system
+ (cons (exception-kind c)
+ (exception-args c)))))
+ ((message-condition? c)
+ (make-warning package
+ (G_ "failed to create ~a derivation: ~a")
+ (list system
+ (condition-message c))))
+ ((formatted-message? c)
+ (let ((str (apply format #f
+ (formatted-message-string c)
+ (formatted-message-arguments c))))
+ (make-warning package
+ (G_ "failed to create ~a derivation: ~a")
+ (list system str)))))
+ (parameterize ((%graft? #f))
+ (package-derivation store package system #:graft? #f)
- ;; If there's a replacement, make sure we can compute its
- ;; derivation.
- (match (package-replacement package)
- (#f #t)
- (replacement
- (package-derivation store replacement system
- #:graft? #f))))))
- (lambda args
- (make-warning package
- (G_ "failed to create ~a derivation: ~s")
- (list system args)))))
+ ;; If there's a replacement, make sure we can compute its
+ ;; derivation.
+ (match (package-replacement package)
+ (#f #t)
+ (replacement
+ (package-derivation store replacement system
+ #:graft? #f))))))
(define (check-with-store store)
(filter lint-warning?
diff --git a/guix/ui.scm b/guix/ui.scm
index 6b0155f563..d3e01f846d 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -812,7 +812,12 @@ directories:~{ ~a~}~%")
;; been unwound when we re-raise, since that would otherwise show
;; useless backtraces.
(((exception-predicate &exception-with-kind-and-args) c)
- (raise c))
+ (if (eq? 'system-error (exception-kind c)) ;EPIPE & co.
+ (match (exception-args c)
+ ((proc format-string format-args . _)
+ (leave (G_ "~a: ~a~%") proc
+ (apply format #f format-string format-args))))
+ (raise c)))
((message-condition? c)
;; Normally '&message' error conditions have an i18n'd message.
@@ -822,12 +827,7 @@ directories:~{ ~a~}~%")
(when (fix-hint? c)
(display-hint (condition-fix-hint c)))
(exit 1)))
- ;; Catch EPIPE and the likes.
- (catch 'system-error
- thunk
- (lambda (key proc format-string format-args . rest)
- (leave (G_ "~a: ~a~%") proc
- (apply format #f format-string format-args))))))
+ (thunk)))
(define-syntax-rule (leave-on-EPIPE exp ...)
"Run EXP... in a context where EPIPE errors are caught and lead to 'exit'
--
2.31.1
next prev parent reply other threads:[~2021-05-26 21:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-26 21:12 [bug#48685] [PATCH 0/2] Require Guile 3.0 Ludovic Courtès
2021-05-26 21:18 ` [bug#48685] [PATCH 1/2] maint: " Ludovic Courtès
2021-05-26 21:18 ` Ludovic Courtès [this message]
2021-06-01 21:28 ` bug#48685: [PATCH 0/2] " Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210526211814.17116-2-ludo@gnu.org \
--to=ludo@gnu.org \
--cc=48685@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).