From patchwork Tue Mar 10 16:03:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 20625 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 0BFCC27BBEA; Tue, 10 Mar 2020 16:04:13 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id AA1BB27BBE4 for ; Tue, 10 Mar 2020 16:04:12 +0000 (GMT) Received: from localhost ([::1]:36410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBhMZ-0000p6-Ok for patchwork@mira.cbaines.net; Tue, 10 Mar 2020 12:04:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45069) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBhMS-0000n2-8r for guix-patches@gnu.org; Tue, 10 Mar 2020 12:04:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBhMQ-0008Cs-VJ for guix-patches@gnu.org; Tue, 10 Mar 2020 12:04:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:47184) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jBhMQ-0008CO-Rw for guix-patches@gnu.org; Tue, 10 Mar 2020 12:04:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jBhMQ-0003a9-LQ for guix-patches@gnu.org; Tue, 10 Mar 2020 12:04:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40016] [PATCH] inferior: Distinguish inferior exceptions. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 10 Mar 2020 16:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 40016 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 40016@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Christopher Baines X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.158385620613725 (code B ref -1); Tue, 10 Mar 2020 16:04:02 +0000 Received: (at submit) by debbugs.gnu.org; 10 Mar 2020 16:03:26 +0000 Received: from localhost ([127.0.0.1]:53156 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jBhLp-0003ZF-QD for submit@debbugs.gnu.org; Tue, 10 Mar 2020 12:03:26 -0400 Received: from lists.gnu.org ([209.51.188.17]:58072) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jBhLn-0003Z5-LY for submit@debbugs.gnu.org; Tue, 10 Mar 2020 12:03:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43650) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBhLl-0008Ft-GK for guix-patches@gnu.org; Tue, 10 Mar 2020 12:03:23 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:38706) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1jBhLi-0006CV-MZ; Tue, 10 Mar 2020 12:03:19 -0400 Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=59682 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jBhLf-0006c0-Fv; Tue, 10 Mar 2020 12:03:16 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Tue, 10 Mar 2020 17:03:05 +0100 Message-Id: <20200310160305.15865-1-ludo@gnu.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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 0236fb61ad..6b685ece30 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! 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)) ; | #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 f54b6d6037..b4417d8629 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 +;;; Copyright © 2018, 2019, 2020 Ludovic Courtès ;;; ;;; 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)