1

I have some customisations in ~/.emacs.el. Today I refactored a piece that used dolist, directory-files, and find-file. I am now unable to quit Emacs in the normal way and I get this from the mini-buffer:

Wrong type argument: hash-table-p, nil

I only have one kill hook, which calls a function mu4e-mark-execute-all defined in mu4e:

(require 'mu4e)
(defun mu4e-execute-marks ()
   (interactive)
   (mu4e-mark-execute-all t)
)
(add-hook 'kill-emacs-hook 'mu4e-execute-marks)

I understand that the LISP debugger is for evaluating expressions or functions. Can I set a stacktrace to see the cause of the error?

Drew
  • 75,699
  • 9
  • 109
  • 225
miguelmorin
  • 1,751
  • 11
  • 33
  • 1
    Where is `mu4e-execute-marks` defined? – muffinmad May 28 '19 at 14:06
  • 1
    You get a backtrace if you switch on "Enter Debugger on Error" in the "Options" menu. You can disable all kill hooks with `M-: (let (kill-emacs-hook) (kill-emacs))`. – Tobias May 28 '19 at 15:01
  • @muffinmad It is defined in [`mu4e`](https://www.djcbsoftware.nl/code/mu/mu4e/) and I updated the question. – miguelmorin May 28 '19 at 15:03
  • @Tobias Your code to remove all hooks actually quits Emacs on macOS. You are right about "Enter Debugger on Error", that's what I wanted, and I found the culprit in `mu4e` throwing an error when it has no marks to execute, so I wrapped the call in `(condition-case ...)`. Do you want to write an answer? – miguelmorin May 28 '19 at 15:22

1 Answers1

3

What is the actual problem and what can I do about it?

The hash is only initialized in mu4e-headers-mode. Therefore, you should correct mu4e-execute-marks in the following way if you want to call it in kill-emacs-hook:

(defun mu4e-execute-marks ()
   (interactive)
   (when (derived-mode-p 'mu4e-headers-mode)
     (mu4e-mark-execute-all t))
)

How to debug such errors?

Switch on "Enter Debugger on Error" in the "Options"-menu. That meu item runs the command toggle-debug-on-error that just toggles the value of the variable debug-on-error between nil and t.

First sentence of the doc of debug-on-error:

Non-nil means enter debugger if an error is signaled.

The debugger includes the backtrace.

Alternatively you can instrument mu4e-mark-execute-all with M-x edebug-on-entry RET mu4e-mark-execute-all RET.

edebug is an interactive debugger. You can step through the function with the space button and you can display the backtrace with the menu item "Edebug"->"Views"->"Show Backtrace".

Tobias
  • 32,569
  • 1
  • 34
  • 75
  • Well done. Your ELisp code executes marks when I quit Emacs from the `mu4e` mode but does not execute marks if I quit outside that mode. – miguelmorin May 28 '19 at 16:20
  • The command `M-x edebug-on-entry` is unavailable on my machine. Is `edebug` available on macOS or only on Linux? – miguelmorin May 28 '19 at 16:21
  • @mmorin Could you try `M-x load-library edebug.el` before calling `edebug-on-entry`? – Tobias May 28 '19 at 20:42
  • That works and `M-x edebug-on-entry` succeeds. I enter the function that throws the error and nothing happens. If I call that same function directly, I see the error `Wrong type argument` in the mini-buffer. – miguelmorin May 29 '19 at 07:38