[Top][All Lists]

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

Displaying errors during startup

From: Lennart Borgman
Subject: Displaying errors during startup
Date: Wed, 26 Apr 2006 17:13:43 +0200
User-agent: Thunderbird (Windows/20060308)

After the recent discussion about error messages at startup (this time it was about pure-space-overflow) it came to my mind I often tend to miss errors at startup. You can not see them because of the splash screen for example. I just started testing `lwarn' because of this. I did something like this:

   (condition-case err
       (require 'something-bad)
      (lwarn '(.emacs) :error "%s" (error-message-string err))))

This displays the error in a nice way even during startup. Looking a bit closer at it it seems to be some trouble with using `pop-to-buffer' in startup.el when loading .emacs. I therefore suggest using `display-buffer' instead like lwarn does. It would also be nice to have a more visible face when putting this in the message buffer. I therefore suggest using something like the code below in startup.el (around line 905):

 (if init-file-debug
     (load inner)
   (condition-case error
       (load inner)
      (let ((message-log-max nil))
          (set-buffer (get-buffer-create "*Messages*"))
          (let ((s
                  (format "An error has occurred while loading `%s':\n\n"
                  (format "%s%s%s"
                          (get (car error) 'error-message)
                          (if (cdr error) ": " "")
(mapconcat (lambda (s) (prin1-to-string s t)) (cdr error) ", "))
"To ensure normal operation, you should investigate and remove the\n" "cause of the error in your initialization file. Start Emacs with\n" "the `--debug-init' option to view a complete error backtrace.\n\n")))
             0 (length s)
             'face 'font-lock-warning-face
            (insert s)
            (insert "\n") ;; Needed to get normal face again.
            (message "Error in init file: %s%s%s"
                     (get (car error) 'error-message)
                     (if (cdr error) ": " "")
                     (mapconcat 'prin1-to-string (cdr error) ", "))
            ;;(let ((pop-up-windows nil))
            ;;  (pop-to-buffer "*Messages*"))
            (display-buffer "*Messages*") ;; display-buffer does the job.
(sit-for 10) ;; sit-for is necessary to display the info at once.
            (setq init-file-had-error t)))))))

Maybe this would be good to do before the release because it makes it somewhat easier to trap errors.

reply via email to

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