Subject: Re: bug#64163: 29.0.92; Syntactic errors in early init when --debug-init is on

From: Stefan Monnier <[email-masked]>
Date: Tue, 20 Jun 2023 13:07:46 -0400

>> IOW `--debug-init` should be the one that sets `debug-ignored-errors` to
>> nil
>
> So you are saying it should be condition on init-file-debug being
> non-nil?

Yup.

> Incidentally, do you happen to know the difference between that
> variable having the value t and 'startup'?

I'm not familiar with this code, no.

AFAICT, `startup` is a special value for `debug-on-error-initial` rather
than for `init-file-debug`.

I expect this is intended to be a value to which noone would set
`debug-on-error`, tho it would make sense to use a more verbose/unlikely
value, both to better detect user settings of `debug-on-error` and to
help document the code.

Maybe something like the patch below (I also renamed the local
variables so they don't look like global variables).

        Stefan

diff --git a/lisp/startup.el b/lisp/startup.el
index 835ad785af1..5b842055c58 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1021,17 +1021,17 @@ startup--load-user-init-file
 
 This function sets `user-init-file' to the name of the loaded
 init-file, or to a default value if loading is not possible."
-  (let ((debug-on-error-from-init-file nil)
-        (debug-on-error-should-be-set nil)
-        (debug-on-error-initial
-         (if (eq init-file-debug t)
-             'startup
-           init-file-debug))
+  (let ((d-o-e-from-init-file nil)
+        (d-o-e-initial
+         (if init-file-debug 'startup--witness debug-on-error))
+        (d-i-e-from-init-file nil)
+        (d-i-e-initial
+         (if init-file-debug '(startup--witness) debug-ignored-errors))
         ;; The init file might contain byte-code with embedded NULs,
         ;; which can cause problems when read back, so disable nul
         ;; byte detection.  (Bug#52554)
         (inhibit-null-byte-detection t))
-    (let ((debug-on-error debug-on-error-initial))
+    (let ((debug-on-error d-o-e-initial))
       (condition-case-unless-debug error
           (when init-file-user
             (let ((init-file-name (funcall filename-function)))
@@ -1112,12 +1112,15 @@ startup--load-user-init-file
 
       ;; If we can tell that the init file altered debug-on-error,
       ;; arrange to preserve the value that it set up.
-      (or (eq debug-on-error debug-on-error-initial)
-          (setq debug-on-error-should-be-set t
-                debug-on-error-from-init-file debug-on-error)))
-
-    (when debug-on-error-should-be-set
-      (setq debug-on-error debug-on-error-from-init-file))))
+      (or (eq debug-on-error d-o-e-initial)
+          (setq d-o-e-from-init-file (list debug-on-error)))
+      (or (eq debug-ignored-errors d-i-e-initial)
+          (setq d-i-e-from-init-file (list debug-ignored-errors))))
+
+    (when d-o-e-from-init-file
+      (setq debug-on-error (car d-o-e-from-init-file)))
+    (when d-i-e-from-init-file
+      (setq debug-ignored-errors (car d-i-e-from-init-file)))))
 
 (defvar lisp-directory nil
   "Directory where Emacs's own *.el and *.elc Lisp files are installed.")