unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Christian Ohler <ohler@gnu.org>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: 11218@debbugs.gnu.org
Subject: bug#11218: with-demoted-errors use of condition-case-unless-debug; ert
Date: Thu, 19 Apr 2012 20:09:29 -0700	[thread overview]
Message-ID: <4F90D369.7070005@gnu.org> (raw)
In-Reply-To: <jwvsjg07lbp.fsf-monnier+emacs@gnu.org>

Stefan Monnier, 2012-04-19:

>>>>>> If you replace with-demoted-errors with ignore-errors, the test passes.
>>>>> Looks like a bug in ERT.
>>>> I don't know if it's a "bug" per se...
>>>> ert--run-test-internal binds debug-on-error to t, and redefines the
>>>> debugger to ert--run-test-debugger. As the doc of that function says:
>>> I wonder why ERT doesn't just use condition-case to catch and record
>>> the errors.
>> Two reasons that I remember off the top of my head: Recording backtraces,
>> and recording additional information provided with `ert-info'.
>
> So the next question is: why does ERT record a backtrace and that extra
> information provided by ert-info?

To be able to show them to the user, together with the test failure.  If 
you have one or more failing tests, it's much more useful to see the 
error messages and backtraces rather than just the error messages.

Unless there's another way to accomplish this, I think it makes sense 
for ERT to bind `debugger'.  Since `debugger' is only called if 
`debug-on-error' is set, ERT has to bind that, too.

I'm not sure where that leaves us.  You could say the problem is that 
`debug-on-error' is overloaded with two different meanings (one in 
eval.c, one in `condition-case-no-debug'), or you could say that ERT 
wants a different `debugger' hook that does not depend on `debug-on-errors'.

But perhaps `with-demoted-errors' and its interaction with 
`debug-on-error' is inherently problematic -- how would we like it to 
interact with tests and debugging?  Assuming ERT did not rebind 
`debug-on-error', the test

   (ert-deftest foo ()
     (with-demoted-errors (error "a"))
     (error "b"))

would normally fail with "b", but if we enable debugging to track down 
why, it will fail with "a" instead (with no way to continue execution to 
get to the error we are interested in).  Confusing.  As far as ERT tests 
are concerned, one could argue that the current behavior (always fail 
with "a") is preferable because it's more consistent; it just means that 
errors in tests can't be demoted.

Fundamentally, having conditionals in the code that explicitly check 
`debug-on-error' seems like asking for trouble.  If the program checks 
"am I being debugged" and behaves differently in that case, we should 
expect testing and debugging tools to break...

And ERT is not the only tool that triggers the problem: While 
investigating this bug, I set `debug-on-error' to nil globally, typed 
M-: (with-demoted-errors (error "foo")) RET, and was confused for a 
moment that I found myself in the debugger with error "foo" -- 
`with-demoted-errors' had no effect.  This is because M-: rebinds 
`debug-on-error' (at least by default).  Just like ERT.  Edebug does the 
same, too.

Christian.






  reply	other threads:[~2012-04-20  3:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-11  3:37 bug#11218: with-demoted-errors use of condition-case-unless-debug; ert Glenn Morris
2012-04-11 12:03 ` Lars Magne Ingebrigtsen
2012-04-11 16:16   ` Glenn Morris
2012-04-11 16:28     ` Glenn Morris
2012-04-11 17:57       ` Stefan Monnier
2012-04-11 13:02 ` Stefan Monnier
2012-04-13  0:15   ` Glenn Morris
2012-04-13 13:44     ` Stefan Monnier
2012-04-17 21:30       ` Christian Ohler
2012-04-19  7:46         ` Stefan Monnier
2012-04-20  3:09           ` Christian Ohler [this message]
2012-04-20 12:13             ` Stefan Monnier
2012-04-20 21:02               ` Christian Ohler
2012-04-21  2:34                 ` Stefan Monnier
2012-04-23 13:26                   ` Lennart Borgman
2012-04-24  2:04                     ` Stefan Monnier
2012-05-06 18:45                   ` Christian Ohler
2012-05-07  1:12                     ` Stefan Monnier
2012-05-21  3:03                       ` Christian Ohler
2018-08-15  1:10         ` Noam Postavsky
2020-11-24 17:34           ` Philipp Stephani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F90D369.7070005@gnu.org \
    --to=ohler@gnu.org \
    --cc=11218@debbugs.gnu.org \
    --cc=monnier@IRO.UMontreal.CA \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).