From debbugs-submit-bounces@debbugs.gnu.org Tue Dec 21 17:44:42 2021 Received: (at submit) by debbugs.gnu.org; 21 Dec 2021 22:44:42 +0000 Received: from localhost ([127.0.0.1]:55982 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mznsA-0007sZ-Fw for submit@debbugs.gnu.org; Tue, 21 Dec 2021 17:44:42 -0500 Received: from lists.gnu.org ([209.51.188.17]:38166) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mzns8-0007sS-NN for submit@debbugs.gnu.org; Tue, 21 Dec 2021 17:44:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzns8-0007qc-60 for guix-patches@gnu.org; Tue, 21 Dec 2021 17:44:40 -0500 Received: from [2a00:1450:4864:20::530] (port=36669 helo=mail-ed1-x530.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzns6-0001LY-Hw for guix-patches@gnu.org; Tue, 21 Dec 2021 17:44:39 -0500 Received: by mail-ed1-x530.google.com with SMTP id z5so1019085edd.3 for ; Tue, 21 Dec 2021 14:44:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6mkQr2zr5wSGL3wTEru24jlpk8vz868hLXUYVZh6bm0=; b=I+e6tHNTQ7TuLO1m7tHP49pgPhex3QdQ1V9YwGkCiCTnnOds4jSBqpsULWrlMMuok8 KqtgdNtIQEYZ2OESqCTIPSoTyRdSMHeIANrR6DNpMyKYFRmYel6eOZhV2+W+H96ujuPk VvxlumUd2W1ndEqAdNICi2IwCD01/5jUefc8C39SsyQx4K0H7xRcNH55fHmrhF3g8erW FjmRNl6ZUmhIZ4f1E3Qh3HVUrr5MB/at/VWRnPzQwmfqgXPqyXxsN5PGgqFifIMX7gMe MrdBjHJt1HrgTM2NWVWKlAtFsomLNG4hj0kfPndHXqagGgTH0hXNUyaRbCiM+QClu8Xl TsNQ== 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 :mime-version:content-transfer-encoding; bh=6mkQr2zr5wSGL3wTEru24jlpk8vz868hLXUYVZh6bm0=; b=Np/YJKb6aL/yYF0BNvLqgE+C8rNTN0JiW6qTY99GizPw+4J3nq213lPv4IaaakPI6Y a0PEWBlJ2eKH1KSZfDQTGAqQHJ7E3MUqD4Lk2FT/0qjPan07Jjdx3/qy9utDLPlMtuhr WjzKNnSu7l62RUB4AstY3DayVISvT1PQ8Ug9gAxXfhl9iJwupHHatjXjdL2PSq3XUW2W 9Iyo3cdjAk0QK1J6Bj6Lu6ZH903JXtwmvRJq5sUmVthe5y6MV5unw8l0BX4GEzXU3IIR /NumD1ny0Ew8QrTLNGSLtkFsrU1X9EpckOfTIcnfbpYSk45Cr3Df6quZ6XzEC+f/RuAD bwlA== X-Gm-Message-State: AOAM5336qmC4cXNz7ZhfLQjisczq6AsVUY9Xbv940um3a7phSpyznp1d 2Ub+siINjCkBKLm1Eo5aUJZsG3Iq9YvuqQ== X-Google-Smtp-Source: ABdhPJyt5N33EkjoiQWT4yqa8vRnM6N0Da73iXImuyOu9UWFGwa2EJ8RjDn5Qfs3ChedcEvE9dRp7g== X-Received: by 2002:a17:907:d8f:: with SMTP id go15mr349312ejc.501.1640126676911; Tue, 21 Dec 2021 14:44:36 -0800 (PST) Received: from localhost.localdomain ([2a02:ab88:3700:b180:6072:12a9:8472:9a8f]) by smtp.gmail.com with ESMTPSA id bx6sm42452edb.78.2021.12.21.14.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 14:44:36 -0800 (PST) From: Attila Lendvai To: guix-patches@gnu.org Subject: [PATCH] guix: Prepare the UI for continuable &warning exceptions. Date: Tue, 21 Dec 2021 23:40:27 +0100 Message-Id: <20211221224029.2091-1-attila@lendvai.name> X-Mailer: git-send-email 2.34.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::530 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::530; envelope-from=attila.lendvai@gmail.com; helo=mail-ed1-x530.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: submit 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: -1.9 (-) * guix/store.scm (call-with-store): Use raise-continuable to resignal exceptions. This is needed for a later commit that uses continuable exceptions from within git-authenticate to signal warnings that are meant to be displayed for the user. The reason for this is that this way unit tests can explicitly check with a handler that a warning was indeed signalled. * guix/ui.scm (call-with-error-handling): Handle &warning type exceptions by printing them to the user, and then continuing at the place where they were signalled at. * guix/diagnostics.scm (emit-formatted-warning): New exported function. --- this is used in an upcoming patch, filed under a separate id. guix/diagnostics.scm | 4 ++++ guix/store.scm | 7 +++++-- guix/ui.scm | 11 ++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/guix/diagnostics.scm b/guix/diagnostics.scm index 337a73c1a2..8e13e5e30a 100644 --- a/guix/diagnostics.scm +++ b/guix/diagnostics.scm @@ -48,6 +48,7 @@ (define-module (guix diagnostics) formatted-message? formatted-message-string formatted-message-arguments + emit-formatted-warning &fix-hint fix-hint? @@ -163,6 +164,9 @@ (define-syntax-rule (leave args ...) (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 a93e9596d9..a2b3b2f05a 100644 --- a/guix/store.scm +++ b/guix/store.scm @@ -34,6 +34,8 @@ (define-module (guix store) #:use-module (guix profiling) #:autoload (guix build syscalls) (terminal-columns) #:use-module (rnrs bytevectors) + #:use-module ((rnrs conditions) #:select (warning?)) + #:use-module ((rnrs exceptions) #:select (raise-continuable)) #:use-module (ice-9 binary-ports) #:use-module ((ice-9 control) #:select (let/ec)) #:use-module (ice-9 atomic) @@ -661,8 +663,9 @@ (define (thunk) (apply values results))))) (with-exception-handler (lambda (exception) - (close-connection store) - (raise-exception exception)) + (unless (warning? exception) + (close-connection store)) + (raise-continuable exception)) thunk))) (define-syntax-rule (with-store store exp ...) diff --git a/guix/ui.scm b/guix/ui.scm index bd999103ff..f492b838d2 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -69,6 +69,8 @@ (define-module (guix ui) #: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) @@ -690,7 +692,14 @@ (define (port-filename* port) (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.34.0 From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 22 11:27:22 2021 Received: (at 52724) by debbugs.gnu.org; 22 Dec 2021 16:27:22 +0000 Received: from localhost ([127.0.0.1]:59591 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n04SY-0001RK-4K for submit@debbugs.gnu.org; Wed, 22 Dec 2021 11:27:22 -0500 Received: from albert.telenet-ops.be ([195.130.137.90]:56244) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n04SV-0001RA-TA for 52724@debbugs.gnu.org; Wed, 22 Dec 2021 11:27:20 -0500 Received: from ptr-bvsjgyhxw7psv60dyze.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:3c5f:2eff:feb0:ba5a]) by albert.telenet-ops.be with bizsmtp id ZUTH2600S4UW6Th06UTHYM; Wed, 22 Dec 2021 17:27:18 +0100 Message-ID: <0bc8e7da7afcd9a3e627a2c3e0306588ab517f0a.camel@telenet.be> Subject: [PATCH] guix: Prepare the UI for continuable &warning exceptions. From: Maxime Devos To: 52724@debbugs.gnu.org Date: Wed, 22 Dec 2021 16:27:17 +0000 Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1640190438; bh=owbE+GbY8nK4VpipA3U/an+I2K4trS9ZKa9rUZ9fOr0=; h=Subject:From:To:Date; b=MyrT8mAeoWpGwJRCZPcWX7ZoPapIeRy6BSrdktIqnnrSG5dFeYg9WibWy+mlvHzA6 cZfJJ4y6Ip7xF4McB6Y2itVyNcTSVWrRnfE81T01O6LnJRnodVvWsFZ3a1LmKlXTKm bcxJCEOpnPSJlTr+CR8jrwSGmSpQPmQA0ZJheIJMOmg6MMQxdNZqS1Nc5/gyjwdKdK SK7/l2uv6Rf6ZBfTtYfA69sQAiCoMhDpOnIcZg6bbrhwBmRGvXJ+qyTaBjJNnNsKnj iL+taLmGjHKG1AN9NRjWvNgPsLK/1alyU7QcuQntCNtSmXwT7ygrMYpb+l3CpxIwwm LtQFnfG/+i4zQ== X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 52724 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: -1.7 (-) Hi, >+ (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)) >+ '()) I think this is better placed right before the 'formatted-message?', instead of before the 'package-input-error?'. Or maybe inside the 'formatted-message?' clause? If you put it inside the 'formatted-message?' clause, you would get fix hint support for free. I don't think the empty list as return value is meaningful here, maybe return nothing at all instead (using (values))? Also, you can't meaningfully stringify a condition. E.g., (display (condition (make-warning) (make-who-condition 'foo))) #<&compound-exception components: (#<&warning> #<&origin origin: foo>)> I don't think "warning: #<& foo:(#<&bar &baz> ...)...>" messages are very useful, so I would simply not handle warning? conditions that aren't formatted-message?. E.g.,: (guard* (c [...] ((and (warning? c) (formatted-message? c)) do-things) [...]) [...]) The downside is that, whenever some code raises a &warning that isn't also a &formatted-message, (guix ui) needs to be adjusted to support it as well, but that's acceptable I think. Also, a test or two would be great (unfortunately call-with-error- handling appears to be untested ...). Greetings, Maxime. From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 23 16:37:12 2021 Received: (at 52724) by debbugs.gnu.org; 23 Dec 2021 21:37:12 +0000 Received: from localhost ([127.0.0.1]:35057 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n0Vlv-0007T8-Tr for submit@debbugs.gnu.org; Thu, 23 Dec 2021 16:37:12 -0500 Received: from mail-ed1-f45.google.com ([209.85.208.45]:44974) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n0Vlu-0007Su-8V for 52724@debbugs.gnu.org; Thu, 23 Dec 2021 16:37:10 -0500 Received: by mail-ed1-f45.google.com with SMTP id w16so26117449edc.11 for <52724@debbugs.gnu.org>; Thu, 23 Dec 2021 13:37:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4K1l0uRsHnuYqJZyvkJW2n64eyXXKf33p6OFmdrccxg=; b=Tgm6XuKy5kP2RcogegUUo304xRBJhnVMQROTUODZc84Qg/5+LXRiLKtrozdA7Ldylz sG5cWy0hIJ7mecZfAAfhINOtnPqnfuduCMU8L41l9ESAzhzZckULclo4QI7U/bqFSY5m zdvmPB1bn5MPdAv6KEN67oFU5kycFUue5unXWjCbvcjKTRSUx9b3mjn6Q2CEWuvDkvNy lfMKw1mzJWtLJQyAZXaRIyHnEYXDfk2g6aRnGXxkoXIsLZS1PZERO9+7ge0PNWSMFAyB Q2ayqBHA+jToF2aUvs415ZhI0TdW0MPQNznT44c90TXE+BVPKlOCv7Ql1VZURxTEAm4q 5ceA== 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 :mime-version:content-transfer-encoding; bh=4K1l0uRsHnuYqJZyvkJW2n64eyXXKf33p6OFmdrccxg=; b=Qz2iMKOEoj7BHRnPCPSzsX+amb+avhWDASreYCc+blrPlcYMqyVujyr+daJqyHI/Pu Bd28/BGS0J5N6kACXRL0x1usBrhk58TvxDUfUlyasuGLNRKAJF/HoMNl6y63xcPDMHlz Eh/SzPssuAhdoP7j6/xyremuEkGMMEvZdboatA6yh/prP/BELnSfr5IXo39gaVT2H+3N BW4De7P74PsCrF/vn1g5++jYm8SG6BL6oAu5IWvcm0JFqBERB+9DM2MeNnVSxcdqQgMy OFmFUhs9AN4Q8n6/jIG2HeFofY1TA2Unbt28YeIqRcmUDJBLcYUpOUuXz2AUYeVoYJ9F yobg== X-Gm-Message-State: AOAM530qgJPH+qe4BmjvX4LQOu5xzMh1v8buAZlXIIZyMZrGrWWHXmLN ljOxgaYUERoX9/pFni4jqDD1SUSG5pyRgQ== X-Google-Smtp-Source: ABdhPJxJiL+yLKW8LjADUm5QMiHJBA19wpeffhvCX0fz675NNjjD0KgJ8G+VlW3EqnCqiccoHRl0Ig== X-Received: by 2002:a05:6402:1203:: with SMTP id c3mr3536114edw.253.1640295424367; Thu, 23 Dec 2021 13:37:04 -0800 (PST) Received: from lelap.lan (catv-80-99-178-127.catv.broadband.hu. [80.99.178.127]) by smtp.gmail.com with ESMTPSA id la26sm2055932ejc.91.2021.12.23.13.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Dec 2021 13:37:03 -0800 (PST) From: Attila Lendvai To: 52724@debbugs.gnu.org Subject: [PATCH v2] guix: Prepare the UI for continuable &warning exceptions. Date: Thu, 23 Dec 2021 22:16:27 +0100 Message-Id: <20211223211626.2753-1-attila@lendvai.name> X-Mailer: git-send-email 2.34.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 52724 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 RAISE-CONTINUABLE to resignal exceptions. This is needed for a later commit that uses continuable exceptions from within GIT-AUTHENTICATE to signal warnings that are meant to be displayed to the user. The reason for this is that this way unit tests can use a handler to explicitly check that a warning was indeed signalled. * guix/ui.scm (call-with-error-handling): Handle &WARNING type exceptions by printing them to the user, and then continuing at the place where they were signalled at. (maybe-display-fix-hint): New procedure. * guix/diagnostics.scm (emit-formatted-warning): New procedure. Exported. --- thanks for the feedback! i've applied everything you pointed out. i didn't merge it with the formatted-message? entry, because i'd like a place where every warning ends up. instead, i have factored out a maybe-display-fix-hint function, and used it there, too. > Also, you can't meaningfully stringify a condition. in case of warnings, you're right. i just have a knee-jerk reaction against silently swallowing errors, and it kicked in here, too. > Also, a test or two would be great i don't really know how to write a test for this. the way i was testing it is that a future commit will add a warning when the channel intro commit doesn't set up .guix-authorizations properly, and i had set up a branch from which i tried to pull. guix/diagnostics.scm | 4 ++++ guix/store.scm | 7 +++++-- guix/ui.scm | 30 ++++++++++++++++++++++++------ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/guix/diagnostics.scm b/guix/diagnostics.scm index 337a73c1a2..8e13e5e30a 100644 --- a/guix/diagnostics.scm +++ b/guix/diagnostics.scm @@ -48,6 +48,7 @@ (define-module (guix diagnostics) formatted-message? formatted-message-string formatted-message-arguments + emit-formatted-warning &fix-hint fix-hint? @@ -163,6 +164,9 @@ (define-syntax-rule (leave args ...) (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 a93e9596d9..a2b3b2f05a 100644 --- a/guix/store.scm +++ b/guix/store.scm @@ -34,6 +34,8 @@ (define-module (guix store) #:use-module (guix profiling) #:autoload (guix build syscalls) (terminal-columns) #:use-module (rnrs bytevectors) + #:use-module ((rnrs conditions) #:select (warning?)) + #:use-module ((rnrs exceptions) #:select (raise-continuable)) #:use-module (ice-9 binary-ports) #:use-module ((ice-9 control) #:select (let/ec)) #:use-module (ice-9 atomic) @@ -661,8 +663,9 @@ (define (thunk) (apply values results))))) (with-exception-handler (lambda (exception) - (close-connection store) - (raise-exception exception)) + (unless (warning? exception) + (close-connection store)) + (raise-continuable exception)) thunk))) (define-syntax-rule (with-store store exp ...) diff --git a/guix/ui.scm b/guix/ui.scm index bd999103ff..96f9db722c 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -69,6 +69,8 @@ (define-module (guix ui) #: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) @@ -299,6 +301,11 @@ (define (module