[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/07: ui, lint: Simplify exception handling in Guile 3 style.
From: |
guix-commits |
Subject: |
02/07: ui, lint: Simplify exception handling in Guile 3 style. |
Date: |
Tue, 1 Jun 2021 17:27:28 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit 5bcb4f8a58ad316174768c167927c03be3272786
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Wed May 26 23:06:13 2021 +0200
ui, lint: Simplify exception handling in Guile 3 style.
* 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 | 72 +++++++++++++++++++++++++++--------------------------------
guix/ui.scm | 14 ++++++------
2 files changed, 40 insertions(+), 46 deletions(-)
diff --git a/guix/lint.scm b/guix/lint.scm
index 023a179..41dd5d0 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)
-
- ;; 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)))))
+ (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))))))
(define (check-with-store store)
(filter lint-warning?
diff --git a/guix/ui.scm b/guix/ui.scm
index 6b0155f..d3e01f8 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'
- branch master updated (49b1570 -> 2df1c4f), guix-commits, 2021/06/01
- 01/07: maint: Require Guile 3.0., guix-commits, 2021/06/01
- 02/07: ui, lint: Simplify exception handling in Guile 3 style.,
guix-commits <=
- 04/07: services: cuirass: Create the profile and GC root directory., guix-commits, 2021/06/01
- 07/07: gnu: rtl8821ce-linux-module: Update to 0.0.0-3.897e7c4., guix-commits, 2021/06/01
- 06/07: machine: ssh: Gracefully handle failure of the effectful bits., guix-commits, 2021/06/01
- 03/07: nls: Translate (guix diagnostics)., guix-commits, 2021/06/01
- 05/07: services: cuirass: Do not export record type descriptors., guix-commits, 2021/06/01