emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can I rethrow an error after recording a backtrace?


From: Clément Pit--Claudel
Subject: Re: How can I rethrow an error after recording a backtrace?
Date: Fri, 5 Aug 2016 11:38:14 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

On 2016-08-05 09:40, Eli Zaretskii wrote:
> But with -daemon, even the first invocation of emacsclient already 
> doesn't display the backtrace, right?  So there's still something 
> different between these two use cases.

Well, it depends what you mean by "display the backtrace": the server doesn't 
respect debug-on-error, but if I register my own debugger, then I *can* capture 
the first backtrace. I have attached a file cpc-server.el that will explain the 
issue better than I can explain it in words (thanks for your patience!). Here's 
how it's used:

    # Start a server, which offers one entry point cpc-eval
    # (cpc-eval form file) evals FORM, captures the output and a backtrace if 
any, and writes it to FILE
    $ emacs -Q -L . -l cpc-server --eval '(setq server-name "cpc")' --daemon
    (...)
    Starting Emacs daemon.

    # This should run (error "A"), record the backtrace, and save it to 
output-for-error-A
    $ emacsclient -s cpc --eval "(cpc-eval '(error \"A\") 
\"output-for-error-A\")"

    # Did it work? Yes: the *Messages* buffer shows that it did: the debugger 
was entered, and properly rethrew the error.
    $ emacsclient -s cpc --eval '(cpc-messages)' | xargs -0 printf
    Starting Emacs daemon.
    Going to eval (error "A") and write to "output-for-error-A"
    Debugger entered with args (error (error "A")) (1 times)
    Condition-case entered with error (error "A")
    Wrote 
/home/clement/.emacs.d/lisp/emacs-syntax-highlighter/example/server-issues/output-for-error-A

    # Just to confirm
    $ cat output-for-error-A
    (error (error "A") "  backtrace()
      (let ((standard-output standard-output)) (backtrace))
      (... long backtrace here; it works! ...)

    # Now let's throw a second error
    $ emacsclient -s cpc --eval "(cpc-eval '(error \"B\") 
\"output-for-error-B\")"

    # Did it work? No: the debugger isn't entered...
    $ emacsclient -s cpc --eval '(cpc-messages)' | xargs -0 printf
    Starting Emacs daemon.
    Going to eval (error "A") and write to "output-for-error-A"
    Debugger entered with args (error (error "A")) (1 times)
    Condition-case entered with error (error "A")
    Wrote 
/home/clement/.emacs.d/lisp/emacs-syntax-highlighter/example/server-issues/output-for-error-A
    Going to eval (error "B") and write to "output-for-error-B"
    Condition-case entered with error (error "B")
    Wrote 
/home/clement/.emacs.d/lisp/emacs-syntax-highlighter/example/server-issues/output-for-error-B

    # And indeed:
    $ cat output-for-error-B
    (error (error "B") nil)

If you uncomment the HACK HACK HACK line in cpc-server, then the second and 
subsequent invocations also work.

I hope this makes everything clear!
Clément.

Attachment: cpc-server.el
Description: Text Data

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]