From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Newsgroups: gmane.emacs.bugs Subject: bug#50629: 28.0.50; hard to debug an uncaught error with ert Date: Sun, 28 Aug 2022 11:27:01 +0200 Message-ID: References: <15445.1631834888@alto> <87pmgncjvg.fsf@gnus.org> <871qt1aklk.fsf@gnus.org> <875yid94k2.fsf@gnus.org> <871qt192vj.fsf@gnus.org> <040ecbba-3db2-44dc-b398-8365c7542dd3@gmail.com> <87ilmdduxu.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40847"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin) Cc: Lars Ingebrigtsen , Mike Kupfer , 50629@debbugs.gnu.org To: Ihor Radchenko Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 28 11:28:17 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 1oSEaX-000ARk-1t for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 28 Aug 2022 11:28:17 +0200 Original-Received: from localhost ([::1]:42904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSEaV-0006qG-Mc for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 28 Aug 2022 05:28:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41104) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSEaI-0006iG-DB for bug-gnu-emacs@gnu.org; Sun, 28 Aug 2022 05:28:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39620) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oSEaI-0000h2-2f for bug-gnu-emacs@gnu.org; Sun, 28 Aug 2022 05:28:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oSEaH-0007CD-QY for bug-gnu-emacs@gnu.org; Sun, 28 Aug 2022 05:28:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 28 Aug 2022 09:28:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50629 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: moreinfo Original-Received: via spool by 50629-submit@debbugs.gnu.org id=B50629.166167883427601 (code B ref 50629); Sun, 28 Aug 2022 09:28:01 +0000 Original-Received: (at 50629) by debbugs.gnu.org; 28 Aug 2022 09:27:14 +0000 Original-Received: from localhost ([127.0.0.1]:57602 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oSEZW-0007B5-0E for submit@debbugs.gnu.org; Sun, 28 Aug 2022 05:27:14 -0400 Original-Received: from mail-wm1-f42.google.com ([209.85.128.42]:37715) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oSEZR-0007Ao-Ak for 50629@debbugs.gnu.org; Sun, 28 Aug 2022 05:27:12 -0400 Original-Received: by mail-wm1-f42.google.com with SMTP id c187-20020a1c35c4000000b003a30d88fe8eso6644045wma.2 for <50629@debbugs.gnu.org>; Sun, 28 Aug 2022 02:27:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc; bh=gVvPzLr+GBJaT1rak8QW5TMSOic8JLgKy3EHBo5mw90=; b=hZVU0rje2+cHEd0p4lD6Wk40o28TCLYCVot2Xt80+79I1BXqxSUVJiltgwhXz0DuAW kWMMdWr5jjV5o7Uhf8pxsHz+K7eCa8JhbnSBtIHbF0VZGocURGLfxPGRP934kiOtqH9x N4XkbwwsqW86thov0hR7/xRDLE1N7kIwkeFDcGBQzMW+ajfmo+QO+KTkXnzfAqgJIcj0 PhWlf8MBum4zlpnAGGK4XNwxg8OL+H3OH6VDyqzUfuhJbi76DH3V902nQwnYfMRXPPEA iYSE4nvQmugDUdmYDOaLMBphF7OEWPuh7fTDRITQJzPZna6bvC4AmJbWqlD4//6gZ9Tj GMlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc; bh=gVvPzLr+GBJaT1rak8QW5TMSOic8JLgKy3EHBo5mw90=; b=o/SFStoXX5lkEHe3u+Rk0y9k+IiwcVLK22kF2z4f1lPDv8VSDVFET7LqNMNHyO6p3b Cj6iPdDB60ZNmiJZQQ1Q3IFd56eUamd04jBI2wQv1ppqBQgA3ks5p8kQpJs/40QosdoQ KfxmpaZ+OZyWfiNK2TbNqOs0i09iJdGN5lh3zNnP5hkitIaGb+IoFtfLA9VCOm0owC2N A5deSJ2lzFQBRtl82hyfKkLddsRHuWki1KupqYTAZQfKg8KnG9F/aZMfquLczl4Qj6rG 9+yIFuiHz8jrjUBBdwJdoMDjeDUCmgPYZuKSY7Ev0fFLgq13o+4CFRUeeC34jLnRwNA/ wZUQ== X-Gm-Message-State: ACgBeo1t7aYMYLh3qr1+aY4ILdFveJkSw3Fggl/e3ilKQgsREyDGSLcU 97npRZ4FqUxAjyJd3DYLw2I= X-Google-Smtp-Source: AA6agR5fTooEB1JhVLYS1dqxFMvhngwwaF8rGoMJhIHC3MkvffaI0X3npCUu4Ax8vqGLavu0XQZXiA== X-Received: by 2002:a05:600c:4ec6:b0:3a5:ff4e:54d4 with SMTP id g6-20020a05600c4ec600b003a5ff4e54d4mr4033125wmq.25.1661678823077; Sun, 28 Aug 2022 02:27:03 -0700 (PDT) Original-Received: from Mini.fritz.box (p4fe3a09f.dip0.t-ipconnect.de. [79.227.160.159]) by smtp.gmail.com with ESMTPSA id l14-20020adfe58e000000b0022377df817fsm4096766wrm.58.2022.08.28.02.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Aug 2022 02:27:02 -0700 (PDT) In-Reply-To: <87ilmdduxu.fsf@localhost> (Ihor Radchenko's message of "Sun, 28 Aug 2022 09:21:33 +0800") 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:240976 Archived-At: Ihor Radchenko writes: > Gerd M=C3=B6llmann writes: > >> On 22-08-27 16:29 , Lars Ingebrigtsen wrote: >>> (args-574 (condition-case err (let ( foo) >>> (list 42 (foo))) >> >> Sorry, you are right, but then the condition-case "swallows" the error. >> Not sure what can be done about that. > > condition-case-unless-debug? Well, that's a nice fretwork :-) When I expand the er-deftest form I get something like this (progn (ert-set-test 'f (record 'ert-test 'f nil #'(lambda nil (setq debug-on-error t) (defalias 'foo #'(lambda nil (bar))) (defalias 'bar #'(lambda nil (zot))) (let* ((fn-339 #'equal) (args-340 (condition-case err (let ((signal-hook-function #'ert--should-signal-hook)) (list 42 (foo))) (error (progn (setq fn-339 #'signal) (list (car err) (cdr err))))))) ... Note the binding of signal-hook-function, which is missing from Lars' expansion result, where is says (let* ((fn-573 #'equal) (args-574 (condition-case err (let ( foo) (list 42 (foo))) (error (progn (setq fn-573 #'signal) (list (car err) (cdr err))))))) I can't explain that. Anyway, let's assume that signal-hook-function is set. and the test is run. This is done in ert--run-test-internal. That function binds debug-on-error to t, and debugger to a lambda invoking ert--run-test-debugger. When our error is signaled, ert--should-signal-hook does nothing because the error is not one of (ert-test-failed ert-test-skipped). So ert--run-test-debugger is not run during the original signal. Not from the signal-hook-function, because it doesn't want to, and not otherwise because of the condition-case. Instead, this part of the test expansion comes into play: (let ((value-341 'ert-form-evaluation-aborted-342)) (let (form-description-343) (if (unwind-protect (setq value-341 (apply fn-339 args-340)) Note that fn-339 has been set to signal in the condition-case. Since debug-on-error is t, the apply in the last line calls signal and we land in ert--run-test-debugger. The debugger than records the backtrace, which is of course not the original backtrace. So, what can we do? I assume there is a good reason that the signal hook function doesn't invoke the debugger? Or in other words, what breaks when the debugger is always invoked, which it would with condition-case-unless-error? (That would be when ert-fail or ert-skip are used in tests.) I don't know. Interestingly with condition-case-unless I get one less error with make check: With condition-case-unless-debug: SUMMARY OF TEST RESULTS ----------------------- Files examined: 445 Ran 6582 tests, 6410 results as expected, 7 unexpected, 165 skipped 5 files contained unexpected results: lisp/subr-tests.log lisp/ls-lisp-tests.log lisp/emacs-lisp/ert-tests.log lisp/emacs-lisp/edebug-tests.log With condition-case: SUMMARY OF TEST RESULTS ----------------------- Files examined: 445 Ran 6582 tests, 6409 results as expected, 8 unexpected, 165 skipped 6 files contained unexpected results: src/process-tests.log lisp/subr-tests.log lisp/ls-lisp-tests.log lisp/emacs-lisp/ert-tests.log lisp/emacs-lisp/edebug-tests.log lisp/emacs-lisp/cl-lib-tests.log Could others try this on their platforms/with their test suites? >From 8154955c5ff056d60b6bcd0b4b2dd234c33f0a75 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Gerd=3D20M=3DC3=3DB6llmann?=3D Date: Sun, 28 Aug 2022 11:23:00 +0200 Subject: [PATCH] Let ERT test definitions use condition-case-unless-debug * lisp/emacs-lisp/ert.el (ert--expand-should-1): Use condition-case-unless-debug in test expansion (bug#50629). --- lisp/emacs-lisp/ert.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el index 047b0069bb..a8fe14aa6d 100644 --- a/lisp/emacs-lisp/ert.el +++ b/lisp/emacs-lisp/ert.el @@ -319,7 +319,9 @@ ert--expand-should-1 (value (gensym "value-")) (default-value (gensym "ert-form-evaluation-aborted-"))) `(let* ((,fn (function ,fn-name)) - (,args (condition-case err + ;; Use condition-case-unless-debug to let the debugger r= ecord + ;; the original backtrace when a signal occurs. + (,args (condition-case-unless-debug err (let ((signal-hook-function #'ert--should-sig= nal-hook)) (list ,@arg-forms)) (error (progn (setq ,fn #'signal) --=20 2.37.2