GNU bug report logs - #65897
29.1.50; Debugging errors surfaced through emacsclient is hard

Previous Next

Package: emacs;

Reported by: Spencer Baugh <sbaugh <at> janestreet.com>

Date: Tue, 12 Sep 2023 19:43:02 UTC

Severity: normal

Found in version 29.1.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Full log


Message #14 received at 65897 <at> debbugs.gnu.org (full text, mbox):

From: Spencer Baugh <sbaugh <at> janestreet.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 65897 <at> debbugs.gnu.org
Subject: Re: bug#65897: 29.1.50; Debugging errors surfaced through
 emacsclient is hard
Date: Fri, 29 Aug 2025 17:02:09 -0400
[Message part 1 (text/plain, inline)]
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>>> Toy example:
>>> 1. emacs -Q
>>> 2. (server-start)
>>> 3. (add-hook 'before-make-frame-hook (lambda () (error "frame hook error")))
>>> 4. emacsclient -c
>>> 
>>> The output of emacsclient is:
>>> 
>>> Waiting for Emacs...
>>> *ERROR*: frame hook error
>>> 
>>> That's all, there is no way to get more information about the error that
>>> happened.
>>> 
>>> Ideally, when emacsclient encounters an error and debug-on-error is
>>> non-nil, it should cause Emacs to enter the debugger.
>>
>> I'm not sure we can allow entering the debugger from server-execute.
>> That function is documented as being called from timers and process
>> filters, so entering the debugger might be unsafe.
>
> AFAIK it is perfectly safe to drop into the debugger when running timers
> and process-filters.  I believe the reason why this doesn't happen here is
> because of the `condition-case` used to grab the error and send it to
> Emacsclient's output.  See patch below.
>
> We could also offer a way to grab the backtrace and send it over to
> Emacsclient's output.
>
>
>         Stefan
>
>
> diff --git a/lisp/server.el b/lisp/server.el
> index 10f15598221..2536a9c6591 100644
> --- a/lisp/server.el
> +++ b/lisp/server.el
> @@ -1175,7 +1175,7 @@ server-process-filter
>      (when prev
>        (setq string (concat prev string))
>        (process-put proc 'previous-string nil)))
> -  (condition-case err
> +  (condition-case-unless-debug err
>        (progn
>  	(server-add-client proc)
>  	;; Send our pid

I tested this and it works for me.  I suggest we should install this.
Here's a modernized version as a patch which applies to trunk.

[0001-Allow-entering-the-debugger-on-error-in-server-conne.patch (text/x-patch, inline)]
From b9aa445c6eb92481ac5b02f69eb99f404aca5cdf Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh <at> janestreet.com>
Date: Fri, 29 Aug 2025 17:00:47 -0400
Subject: [PATCH] Allow entering the debugger on error in server connection

* lisp/server.el (server--process-filter-1): Use
condition-case-unless-debug. (bug#65897)
---
 lisp/server.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/server.el b/lisp/server.el
index 4415c45971e..70299d52f18 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -1232,7 +1232,7 @@ server--process-filter-1
     (when prev
       (setq string (concat prev string))
       (process-put proc 'previous-string nil)))
-  (condition-case err
+  (condition-case-unless-debug err
       (progn
 	(server-add-client proc)
 	;; Send our pid
-- 
2.43.7


This bug report was last modified 19 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.