From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 28 12:27:01 2021 Received: (at 50814) by debbugs.gnu.org; 28 Sep 2021 16:27:01 +0000 Received: from localhost ([127.0.0.1]:46787 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mVFwb-0005a8-1h for submit@debbugs.gnu.org; Tue, 28 Sep 2021 12:27:01 -0400 Received: from mail-ed1-f52.google.com ([209.85.208.52]:38784) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mVFwY-0005Zi-SN for 50814@debbugs.gnu.org; Tue, 28 Sep 2021 12:26:59 -0400 Received: by mail-ed1-f52.google.com with SMTP id dj4so85972042edb.5 for <50814@debbugs.gnu.org>; Tue, 28 Sep 2021 09:26:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rjf4e4gbvvXnkiZqzq7K+EMEhoVB7jqYYfKwKV96M0c=; b=fqUOctpvf5IRH2IolRHtaz3SHCv80Syj88dNvRMOdW0Y42GLX4vG/2Ij7TPk/1c0Li eiSpdfQRNFkv7Bpvdj92qcHmdLOcMsRp4lBOx7hzdxsrJOjlXYX1sNiyK8L5wQTqRkI+ WjFxLhyP50vQaEAYOsFDG/Eh92OPETXN7XKNi1R9T0WlI8wdOXAfkQhBqwnxXR96d/CX 9TJpXz2mT0R+4if0ZrnvlMTlkXb+O0/fp39u+BDuVS7qRr/fI+C3qQQeEaRxdmsje9y8 txxueQGT4/Tnp4T6qXDK9FJQINSDJUiC+dQZcaXg5+flczSQ5Fs5zfQwlXIq10+2B4BG KKlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Rjf4e4gbvvXnkiZqzq7K+EMEhoVB7jqYYfKwKV96M0c=; b=kabtJJkdTf+Vrut+xdjVG6T7dmXzVVeKMZ5eJ6sZyOTEusYYdM/8M7adV8DfEc4KFu RRJLLE8gGr3RE6TYkmmR44kQ651YrhKeG+B9OqAK3kYkRHC8ttJoBTC8TRU46gKvzmbs NuLULefZsGpKDeLpo2HM96C153XlggtOgu1/tsctBswDmU3PLi62p0La2TpfeSpEf1Zg fwWrOUwUB92mL/D22UvWloWsnB9VFRiz3vOEETYPkV+WT2GXxV4ecKaGCdc6Z0tSlTjr BdxBN+q2Col5nQyf+7BZKbk5QvnpAD/M4id04GVwMz9OArSczPIcgCFVeYXevCRw3RNB H+aA== X-Gm-Message-State: AOAM531AYyBHa97Eo3xKsUcDxvLBQZ/ayFifYlbrENVnOvjnXbjio59L mjlqGWFlS9eKqcIMPT9yO4hU991hV9o= X-Google-Smtp-Source: ABdhPJxt5u2NcW+1G+w8vC2WZMhZkHv9OkpLEjcrel8aMhjMkgMFT5x0lvJD8G4zCzphwBz0xAHwOg== X-Received: by 2002:a17:907:9686:: with SMTP id hd6mr3608988ejc.331.1632846412631; Tue, 28 Sep 2021 09:26:52 -0700 (PDT) Received: from lelap.lan (catv-213-222-131-28.catv.broadband.hu. [213.222.131.28]) by smtp.gmail.com with ESMTPSA id f4sm3147720ejq.125.2021.09.28.09.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 09:26:52 -0700 (PDT) From: Attila Lendvai To: 50814@debbugs.gnu.org Subject: [PATCH 4/5] guix: Prepare the UI for continuable &warning exceptions. Date: Tue, 28 Sep 2021 18:24:06 +0200 Message-Id: <20210928162406.27205-4-attila@lendvai.name> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210928162406.27205-1-attila@lendvai.name> References: <20210928162406.27205-1-attila@lendvai.name> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 50814 Cc: Attila Lendvai X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.5 (/) * guix/store.scm (call-with-store): Use dynamic-wind so that continuable exceptions are not broken by being re-raised as non-continuable. This is needed for a later commit that uses continuable exceptions from within git-authenticate to signal warnings to the user. The reason for this is that this way tests can explicitly check that a warning was signalled in certain situations. * guix/ui.scm (call-with-error-handling): Handle &warning type exceptions by printing them to the user, and then continuing at the place they were signalled at. * guix/diagnostics.scm (emit-formatted-warning): New exported function. --- guix/diagnostics.scm | 4 ++++ guix/store.scm | 16 ++++++++++------ guix/ui.scm | 11 ++++++++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/guix/diagnostics.scm b/guix/diagnostics.scm index 6a792febd4..343213fb45 100644 --- a/guix/diagnostics.scm +++ b/guix/diagnostics.scm @@ -48,6 +48,7 @@ formatted-message? formatted-message-string formatted-message-arguments + emit-formatted-warning &fix-hint fix-hint? @@ -161,6 +162,9 @@ messages." (report-error args ...) (exit 1))) +(define* (emit-formatted-warning fmt . args) + (emit-diagnostic fmt args #:prefix (G_ "warning: ") #:colors %warning-color)) + (define* (emit-diagnostic fmt args #:key location (colors (color)) (prefix "")) "Report diagnostic message FMT with the given ARGS and the specified diff --git a/guix/store.scm b/guix/store.scm index 89a719bcfc..33d4039037 100644 --- a/guix/store.scm +++ b/guix/store.scm @@ -45,6 +45,8 @@ #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) #:use-module (srfi srfi-39) + #:use-module ((rnrs conditions) + #:select (warning?)) #:use-module (ice-9 match) #:use-module (ice-9 vlist) #:use-module (ice-9 popen) @@ -651,19 +653,21 @@ connection. Use with care." (define (call-with-store proc) "Call PROC with an open store connection." - (let ((store (open-connection))) + (let ((store '())) (define (thunk) (parameterize ((current-store-protocol-version (store-connection-version store))) (call-with-values (lambda () (proc store)) (lambda results - (close-connection store) (apply values results))))) - (with-exception-handler (lambda (exception) - (close-connection store) - (raise-exception exception)) - thunk))) + (dynamic-wind + (lambda () + (set! store (open-connection))) + thunk + (lambda () + (close-connection store) + (set! store '()))))) (define-syntax-rule (with-store store exp ...) "Bind STORE to an open connection to the store and evaluate EXPs; diff --git a/guix/ui.scm b/guix/ui.scm index 1428c254b3..88940f99ef 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -69,6 +69,8 @@ #:use-module (srfi srfi-31) #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) + #:use-module ((rnrs conditions) + #:select (warning?)) #:autoload (ice-9 ftw) (scandir) #:use-module (ice-9 match) #:use-module (ice-9 format) @@ -689,7 +691,14 @@ evaluating the tests and bodies of CLAUSES." (and (not (port-closed? port)) (port-filename port))) - (guard* (c ((package-input-error? c) + (guard* (c ((warning? c) + (if (formatted-message? c) + (apply emit-formatted-warning + (formatted-message-string c) + (formatted-message-arguments c)) + (emit-formatted-warning "~a" c)) + '()) + ((package-input-error? c) (let* ((package (package-error-package c)) (input (package-error-invalid-input c)) (location (package-location package)) -- 2.33.0