Subject: Re: bug#65763: Error opening a file from a Git working directory if Git is not installed

From: Eli Zaretskii <[email-masked]>
Date: Sun, 10 Sep 2023 09:26:01 +0300

> Date: Wed, 6 Sep 2023 18:59:00 +0300
> Cc: [email-masked], [email-masked]
> From: Dmitry Gutov <[email-masked]>
> 
> On 06/09/2023 18:46, Eli Zaretskii wrote:
> > I prefer to emit the messages, just make them more user-friendly
> > ("searching for program" "no such file or directory" is not very
> > friendly, IMO), and suppress the error signaling even when
> > debug-on-error is non-nil.  The reason is simple: we are talking only
> > about Git not being installed or accessible here, but the problems
> > could be different and more obscure: Git could be present but
> > inoperable for some weird misconfiguration reason, or some other
> > problem could happen.  So "if it is not installed, just silently don't
> > do anything" is not a complete solution, and the "silently" part loses
> > information which users may wish to have presented to them.
> 
> That also sounds good to me.

There's something strange going on here: even if I wrap the call to
vc-backend with ignore-errors (see the patch below), I still see the
error message, and running with debug-on-error enters the debugger:

  ./emacs --batch --eval "(let ((debug-on-error t)) (setf vc-git-program \"git-is-not-installed\") (find-file-noselect \"README\"))"
  Debugger entered--Lisp error: (file-missing "Searching for program" "No such file or directory" "git-is-not-installed")
    call-process("git-is-not-installed" nil (t nil) nil "--no-pager" "ls-files" "-c" "-z" "--" "src/README")
    apply(call-process "git-is-not-installed" nil (t nil) nil ("--no-pager" "ls-files" "-c" "-z" "--" "src/README"))
    process-file("git-is-not-installed" nil (t nil) nil "--no-pager" "ls-files" "-c" "-z" "--" "src/README")
    apply(process-file "git-is-not-installed" nil (t nil) nil "--no-pager" "ls-files" ("-c" "-z" "--" "src/README"))
    vc-git--call((t nil) "ls-files" "-c" "-z" "--" "src/README")
    apply(vc-git--call (t nil) "ls-files" ("-c" "-z" "--" "src/README"))
    vc-git--out-ok("ls-files" "-c" "-z" "--" "src/README")
    vc-git-registered("d:/gnu/git/emacs/trunk/src/README")
    vc-git-registered("d:/gnu/git/emacs/trunk/src/README")
    apply(vc-git-registered "d:/gnu/git/emacs/trunk/src/README")
    vc-call-backend(Git registered "d:/gnu/git/emacs/trunk/src/README")
    #f(compiled-function (b) #<bytecode 0x1b9bb8e1e734a02c>)(Git)
    mapc(#f(compiled-function (b) #<bytecode 0x1b9bb8e1e734a02c>) (RCS CVS SVN SCCS SRC Bzr Git Hg))
    vc-registered("d:/gnu/git/emacs/trunk/src/README")
    vc-backend("d:/gnu/git/emacs/trunk/src/README")
    vc-refresh-state()
    run-hooks(find-file-hook)
    after-find-file(nil t)
    find-file-noselect-1(#<buffer README> "d:/gnu/git/emacs/trunk/src/README" nil nil "d:/gnu/git/emacs/trunk/src/README" (8444249302351936 1817014650))
    find-file-noselect("README")
    (let ((debug-on-error t)) (setf vc-git-program "git-is-not-installed") (find-file-noselect "README"))
    eval((let ((debug-on-error t)) (setf vc-git-program "git-is-not-installed") (find-file-noselect "README")) t)
    command-line-1(("--eval" "(let ((debug-on-error t)) (setf vc-git-program \"gi..."))
    command-line()
    normal-top-level()

It looks like condition-case is not working in this case?  Or what am
I missing?

Stefan, can you help?

Here's the patch I installed to try this, and it still produces the
backtrace shown above, which clearly tells the error was signaled by
subroutines called by vc-backend:

diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el
index a4de0a6..0715236 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -799,7 +799,7 @@ vc-refresh-state
     (add-hook 'vc-mode-line-hook #'vc-mode-line nil t)
     (let (backend)
       (cond
-       ((setq backend (with-demoted-errors "VC refresh error: %S"
+       ((setq backend (ignore-errors
                         (vc-backend buffer-file-name)))
         ;; Let the backend setup any buffer-local things he needs.
         (vc-call-backend backend 'find-file-hook)