[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
05/09: inferior: Distinguish inferior exceptions.
From: |
guix-commits |
Subject: |
05/09: inferior: Distinguish inferior exceptions. |
Date: |
Thu, 12 Mar 2020 06:52:50 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit f7537e30b892cef09d91902547c00e5fa9b66f3b
Author: Ludovic Courtès <address@hidden>
AuthorDate: Tue Mar 10 16:45:57 2020 +0100
inferior: Distinguish inferior exceptions.
This avoids ambiguities when looking at a backtrace where the exception
was actually thrown by an inferior in a very different context.
* guix/inferior.scm (&inferior-exception): New condition type.
(read-repl-response): Add optional 'inferior' parameter. Raise
'&inferior-exception' instead of rethrowing to KEY when receiving an
'exception' message.
(read-inferior-response): Pass INFERIOR to 'read-repl-response'.
* tests/inferior.scm ("&inferior-exception"): New test.
---
guix/inferior.scm | 21 +++++++++++++++++----
tests/inferior.scm | 13 ++++++++++++-
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/guix/inferior.scm b/guix/inferior.scm
index 0236fb6..6b685ec 100644
--- a/guix/inferior.scm
+++ b/guix/inferior.scm
@@ -63,6 +63,9 @@
inferior-eval
inferior-eval-with-store
inferior-object?
+ inferior-exception?
+ inferior-exception-arguments
+ inferior-exception-inferior
read-repl-response
inferior-packages
@@ -195,8 +198,15 @@ equivalent. Return #f if the inferior could not be
launched."
(set-record-type-printer! <inferior-object> write-inferior-object)
-(define (read-repl-response port)
- "Read a (guix repl) response from PORT and return it as a Scheme object."
+;; Reified exception thrown by an inferior.
+(define-condition-type &inferior-exception &error
+ inferior-exception?
+ (arguments inferior-exception-arguments) ;key + arguments
+ (inferior inferior-exception-inferior)) ;<inferior> | #f
+
+(define* (read-repl-response port #:optional inferior)
+ "Read a (guix repl) response from PORT and return it as a Scheme object.
+Raise '&inferior-exception' when an exception is read from PORT."
(define sexp->object
(match-lambda
(('value value)
@@ -208,10 +218,13 @@ equivalent. Return #f if the inferior could not be
launched."
(('values objects ...)
(apply values (map sexp->object objects)))
(('exception key objects ...)
- (apply throw key (map sexp->object objects)))))
+ (raise (condition (&inferior-exception
+ (arguments (cons key (map sexp->object objects)))
+ (inferior inferior)))))))
(define (read-inferior-response inferior)
- (read-repl-response (inferior-socket inferior)))
+ (read-repl-response (inferior-socket inferior)
+ inferior))
(define (send-inferior-request exp inferior)
(write exp (inferior-socket inferior))
diff --git a/tests/inferior.scm b/tests/inferior.scm
index f54b6d6..b4417d8 100644
--- a/tests/inferior.scm
+++ b/tests/inferior.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2018, 2019 Ludovic Courtès <address@hidden>
+;;; Copyright © 2018, 2019, 2020 Ludovic Courtès <address@hidden>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -61,6 +61,17 @@
(close-inferior inferior)
(list a (inferior-object? b))))))
+(test-equal "&inferior-exception"
+ '(a b c d)
+ (let ((inferior (open-inferior %top-builddir
+ #:command "scripts/guix")))
+ (guard (c ((inferior-exception? c)
+ (close-inferior inferior)
+ (and (eq? inferior (inferior-exception-inferior c))
+ (inferior-exception-arguments c))))
+ (inferior-eval '(throw 'a 'b 'c 'd) inferior)
+ 'badness)))
+
(test-equal "inferior-packages"
(take (sort (fold-packages (lambda (package lst)
(cons (list (package-name package)
- branch master updated (ec73c90 -> 0a703c0), guix-commits, 2020/03/12
- 01/09: gnu: guile-next: Enable JIT on ARMv7., guix-commits, 2020/03/12
- 02/09: import: pypi: Rewrite to use 'define-json-mapping'., guix-commits, 2020/03/12
- 03/09: import: utils: Remove 'assoc-ref*'., guix-commits, 2020/03/12
- 06/09: gnu: dune-*: set up MPI for tests, guix-commits, 2020/03/12
- 05/09: inferior: Distinguish inferior exceptions.,
guix-commits <=
- 07/09: gnu: Add dune-uggrid., guix-commits, 2020/03/12
- 09/09: gnu: dune-istl: Build with suitesparse, guix-commits, 2020/03/12
- 08/09: gnu: Add dune-subgrid, guix-commits, 2020/03/12
- 04/09: import: cpan: Gracefully handle missing projects., guix-commits, 2020/03/12