From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.bugs Subject: bug#66326: 29.1.50; There should be a way to promote warnings to errors Date: Wed, 04 Oct 2023 08:20:49 -0400 Message-ID: References: <83y1gj5ya9.fsf@gnu.org> <87wmw3zfd3.fsf@catern.com> <83wmw353ny.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25313"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: sbaugh@catern.com, 66326@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 04 14:22:15 2023 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 1qo0tL-0006Ir-81 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 04 Oct 2023 14:22:15 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qo0t0-0000YL-JZ; Wed, 04 Oct 2023 08:21:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qo0sr-0000XM-GS for bug-gnu-emacs@gnu.org; Wed, 04 Oct 2023 08:21:46 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qo0sr-0003LZ-8H for bug-gnu-emacs@gnu.org; Wed, 04 Oct 2023 08:21:45 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qo0t7-0004Pz-Lh for bug-gnu-emacs@gnu.org; Wed, 04 Oct 2023 08:22:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 04 Oct 2023 12:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66326 X-GNU-PR-Package: emacs Original-Received: via spool by 66326-submit@debbugs.gnu.org id=B66326.169642207516904 (code B ref 66326); Wed, 04 Oct 2023 12:22:01 +0000 Original-Received: (at 66326) by debbugs.gnu.org; 4 Oct 2023 12:21:15 +0000 Original-Received: from localhost ([127.0.0.1]:41767 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qo0sM-0004OX-F1 for submit@debbugs.gnu.org; Wed, 04 Oct 2023 08:21:14 -0400 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]:32837) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qo0sL-0004OI-1w for 66326@debbugs.gnu.org; Wed, 04 Oct 2023 08:21:13 -0400 In-Reply-To: <83wmw353ny.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 04 Oct 2023 08:59:13 +0300") 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:271795 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: > And in this case, duplication is a lesser evil than reordering of > logic, since the chances of unintended consequences would be lower in > the former case. OK, how about this version then? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Support-turning-warnings-into-errors.patch >From 11fdd0cdd2d0da28848ad42d8087ebb1a4e05430 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Tue, 3 Oct 2023 14:36:25 -0400 Subject: [PATCH] Support turning warnings into errors Support turning warnings into errors in a user-configurable way. This is especially useful in combination with (setq debug-on-error t) to drop to the debugger when a warning happens. * lisp/emacs-lisp/warnings.el (warning-suppress-types): Improve docstring. (warning-to-error-types, warning-to-error): Add. (display-warning): Check warning-to-error-types. --- lisp/emacs-lisp/warnings.el | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lisp/emacs-lisp/warnings.el b/lisp/emacs-lisp/warnings.el index 31b840d6c83..0e8464c4455 100644 --- a/lisp/emacs-lisp/warnings.el +++ b/lisp/emacs-lisp/warnings.el @@ -114,11 +114,20 @@ warning-suppress-types The element must match an initial segment of the list TYPE. Thus, (foo bar) as an element matches (foo bar) or (foo bar ANYTHING...) as TYPE. +An empty list as an element matches any TYPE. If TYPE is a symbol FOO, that is equivalent to the list (FOO), so only the element (FOO) will match it. See also `warning-suppress-log-types'." :type '(repeat (repeat symbol)) :version "22.1") + +(defcustom warning-to-error-types nil + "List of warning types to signal as an error instead. +If any element of this list matches the TYPE argument to `display-warning', +`display-warning' signals an error instead of logging a warning. +See `warning-suppress-types' for the format of elements in this list." + :type '(repeat (repeat symbol)) + :version "30.1") ;; The autoload cookie is so that programs can bind this variable ;; safely, testing the existing value, before they call one of the @@ -230,6 +239,14 @@ warnings-suppress (cons (list type) warning-suppress-types))) (_ (message "Exiting")))) +(defun warning-to-error (type message level) + (unless level + (setq level :warning)) + (let* ((typename (if (consp type) (car type) type)) + (level-info (assq level warning-levels))) + (error (nth 1 level-info) + (format warning-type-format typename)))) + ;;;###autoload (defun display-warning (type message &optional level buffer-name) "Display a warning message, MESSAGE. @@ -263,6 +280,11 @@ display-warning disable automatic display of the warning or disable the warning entirely by setting `warning-suppress-types' or `warning-suppress-log-types' on their behalf." + (when (and (> (warning-numeric-level (or level :warning)) + (warning-numeric-level warning-minimum-log-level)) + (not (warning-suppress-p type warning-suppress-log-types)) + (warning-suppress-p type warning-to-error-types)) + (warning-to-error type message level)) (if (not (or after-init-time noninteractive (daemonp))) ;; Ensure warnings that happen early in the startup sequence ;; are visible when startup completes (bug#20792). -- 2.39.3 --=-=-=--