From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#57407: [PATCH] Handle error of =?UTF-8?Q?=E2=80=99vc-registered=E2=80=99?= Date: Mon, 12 Sep 2022 04:08:23 +0300 Message-ID: References: <87lercwb0o.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20181"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 To: Simon Tournier , 57407@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 12 03:09:13 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oXXwm-00057N-Pw for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 12 Sep 2022 03:09:12 +0200 Original-Received: from localhost ([::1]:46742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXXwl-00010U-K0 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 11 Sep 2022 21:09:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41728) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXXwc-00010D-7x for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2022 21:09:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55058) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oXXwb-0000mz-S7 for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2022 21:09:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oXXwb-0005tV-JG for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2022 21:09:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Sep 2022 01:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57407 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch moreinfo Original-Received: via spool by 57407-submit@debbugs.gnu.org id=B57407.166294491422622 (code B ref 57407); Mon, 12 Sep 2022 01:09:01 +0000 Original-Received: (at 57407) by debbugs.gnu.org; 12 Sep 2022 01:08:34 +0000 Original-Received: from localhost ([127.0.0.1]:43757 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXXw9-0005so-WA for submit@debbugs.gnu.org; Sun, 11 Sep 2022 21:08:34 -0400 Original-Received: from mail-wm1-f48.google.com ([209.85.128.48]:55135) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXXw7-0005sW-4D for 57407@debbugs.gnu.org; Sun, 11 Sep 2022 21:08:32 -0400 Original-Received: by mail-wm1-f48.google.com with SMTP id az6so6149792wmb.4 for <57407@debbugs.gnu.org>; Sun, 11 Sep 2022 18:08:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date; bh=LmF3+DY8hXZQJTi4E73jAJDca2Jw4wbgo+88OKpIxNU=; b=fWPNWQBkWlGR5srGYUYUleu1R2vNND4cpsMduzqJt/2ipiJ5D/2lADWjNx88D5fPma Cl4AFb6sP0n940J+sIn/vh0niKS/+hXmX1omhGds6dvq/chanqQBhdEPNp75N5ZI1S/9 50KT1YyL0nrmwwHCk2/FZjo9D4asz/uNKDyqcihvHZS+/Uv1dY4Tmn8u7nCfwVAQIoaP sfPvmHxS3cUmKDldJYCYTTXDnSAz2yG8FPGs71PFStKwLDMa9+EaFc3VFFhICgynshV7 WneDHIAr+NYaTixPNqoNTBZJrYXruAnPAb8Z8Yzuj7G/SVQOSvNPhVTJxEf3iPcCikoB GTNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date; bh=LmF3+DY8hXZQJTi4E73jAJDca2Jw4wbgo+88OKpIxNU=; b=cuO+wJGr1ANHPdzDPDe018l+VtkYcboNtrAMqgU126hiFv8WgKnHaLDiZO3AZtFXUu pZ2gVriF7XrwpsZiLUUv8n1m45EI027M8Lg6SQmgQPPtlpxiuBv7ogxkf3dS81oPRdtE hlkSJDAjDwp3PhtJ9L3X5Hzln0DMguSCVJUrMG64ouicixgjb44NlbKpEywIdEBy/2R2 ulM0HmXOKGrrjyKVFF1TUpRdqoe+zAi/DJvVMMKAa3qbM3pYLzM0hvW9LDS5Jwy22WDX rbuMGTclBKQ88RElVcAMxmnA2F+VZeGAQHpiZfOIaDfTt5mkGAHzfffHN+IVnJEkB2C6 UPjQ== X-Gm-Message-State: ACgBeo0h8aPyfychvzxgMC4UOiWahLUsi8wVvpkEyjVeyGEHikAWOOeP 8mlqZRLYQRJ7t9pafjiVSY0= X-Google-Smtp-Source: AA6agR7ityX+4OKS0Fda3AIEmpm3cMFwRzBjLPnsQBZxvB+CBUYCkbMmNEpkm3esRDfHwYV7dL+c5Q== X-Received: by 2002:a05:600c:4ec7:b0:3a8:4622:ad27 with SMTP id g7-20020a05600c4ec700b003a84622ad27mr12806371wmq.88.1662944905109; Sun, 11 Sep 2022 18:08:25 -0700 (PDT) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id g14-20020a05600c4ece00b003a4c6e67f01sm8733625wmq.6.2022.09.11.18.08.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Sep 2022 18:08:24 -0700 (PDT) Content-Language: en-US In-Reply-To: <87lercwb0o.fsf@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:242203 Archived-At: Hi! On 25.08.2022 19:20, Simon Tournier wrote: > Hi, > > Submission (Bug#18481) [0] merged on 2020-08-13 with commit > 991e145450ec8b02865597bc80fd797e39e81f07 [1] aims to: > > “Notify the user if we errors when querying for registered git files“ > > However, the replacement of ’ignore-errors’ by ’with-demoted-errors’ > introduces spurious messages. This patch proposes to handle the errors > in a way that: > > 1. the user is still informed (avoid silent error) > 2. improve the messages trying to be more accurate > 3. do it for all the VC backends > > 0: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=18481 > 1: https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=991e145450ec8b02865597bc80fd797e39e81f07 > > > > First, let compare the previous situation with the patched one. If the > user runs ’find-file’ in a Git repository without having installed the > Git binary, then Emacs complains and the error is misleading. > Reproducer: > > --8<---------------cut here---------------start------------->8--- > $ which git > which: no git in … > $ mkdir -p /tmp/Git/.git > $ emacs -q --batch --eval="(find-file \"/tmp/Git/foo\")" > Error: (file-missing "Searching for program" "No such file or directory" "git") > Package vc-mtn is deprecated > --8<---------------cut here---------------end--------------->8--- > > Not having a working Git installation is not an error for opening one > file belonging to a folder containing a ’.git’ subdirectory. For > instance, if an user processes many files reporting many messages, then > it seems hard to locate the real error, if any. Do I take this right that the main purpose of the patch is to have the "Error: ..." messages replaced with "Warning: ..."? > Moreover, the messages are inconsistent depending on the VC backend; > from nothing reported to a backtrace. > > --8<---------------cut here---------------start------------->8--- > $ mkdir -p /tmp/Bzr/.bzr > $ emacs -q --batch --eval="(find-file \"/tmp/Bzr/foo\")" > Error: (file-missing "Searching for program" "No such file or directory" "bzr") > Error: (file-missing "Searching for program" "No such file or directory" "bzr") > > Error: file-missing ("Searching for program" "No such file or directory" "bzr") > > [...] > > Searching for program: No such file or directory, bzr > --8<---------------cut here---------------end--------------->8--- > > Considering the patch, it would become: > > --8<---------------cut here---------------start------------->8--- > $ emacs -q --batch --eval="(find-file \"/tmp/Git/foo\")" > Warning: (vc-not-supported "Searching for program" "No such file or directory" "git") > > $ emacs -q --batch --eval="(find-file \"/tmp/Bzr/foo\")" > Falling back on "slow" status detection ((error . "VC: Bzr dirstate is not flat format 3")) > Warning: (vc-not-supported "Searching for program" "No such file or directory" "bzr") > --8<---------------cut here---------------end--------------->8--- > > and all the VC backends report similarly when something fails. Some better consistency would be nice indeed. > Second, I have tested various configurations using Guix (65cabb0) and > also the Emacs test suite is passing. However, note that a) I barely > use VC so b) I am lacking imagination for testing scenarii where the > bubble error could wrongly propagate and thus would provide an > unexpected behavior. Especially with remote as Tramp allows. > > > Third, I do not know if it is the correct way for catching the errors. > The core of the change is: > > --8<---------------cut here---------------start------------->8--- > lisp/vc/vc-dispatcher.el (vc-do-command): > > (condition-case err > (setq status (apply #'process-file command nil t nil squeezed)) > (error > (pcase (car err) > ('file-missing > (if (string= (cadr err) "Searching for program") > ;; The most probable is the lack of the backend binary. > (signal 'vc-not-supported (cdr err)) > (signal (car err) (cdr err)))) > (_ > (signal (car err) (cdr err)))))) > > lisp/vc/vc-hooks.el (vc-refresh-state): > > (condition-case err > (vc-backend buffer-file-name) > (error > (pcase (car err) > ('vc-not-supported > (message "Warning: %S" err)) > (_ > (message "VC refresh error: %S" err))) > nil)) > --8<---------------cut here---------------end--------------->8--- > > and the rest of the change is just bubble error propagation from this > ’vc-do-command’ to this ’vc-refresh-state’. This general idea seems reasonable. But you also add a bunch of re-signaling code like + (let ((state (condition-case err + (vc-bzr-state-heuristic file) + (error (signal (car err) (cdr err)))))) What is the idea behind this? Why not just keep the call? And in vc-svn-registered, for example. You re-signal whatever error is caught, without any alternative. Do we need the condition-case there at all, then? Furthermore, we'll have to examine the resulting effect on the behavior of various backend methods. Apparently, up until now vc-svn-registered never signaled an error (swallowed all of them). And now whatever callers it has, will need to handle possible errors. It's probably fine, though. vc-backend is a more popular function, and it seems not much is changing for it, since, for some reason, vc-refresh-state wrapped its call in with-demoted-errors anyway. But I think we have other callers of it in-tree, and not all of them guard with with-demoted-errors or condition-case. What do you think we should do with them? > It is probably an abuse of ’pcase’. Is ’cond’ better here? Last, > I have not found in the documentation how to differentiate what it is > raised depending on the error type, hence the ’pcase’. I think you just need to write the specific error type instead of 'error' in the handler clause. Regarding the rest of the patch, could you explain the change in vc-bzr-state-heuristic? Looking at the code, I figure the idea was to future-proof the parser against some future change in file format, to fall back to (slower) calling the 'bzr' program. Are we somehow certain now this is not needed?