0

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?

  • 1
    Where is mu4e-execute-marks defined? – muffinmad May 28 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 at 15:01
  • @muffinmad It is defined in mu4e and I updated the question. – mmorin May 28 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? – mmorin May 28 at 15:22
1

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".

  • 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. – mmorin May 28 at 16:20
  • The command M-x edebug-on-entry is unavailable on my machine. Is edebug available on macOS or only on Linux? – mmorin May 28 at 16:21
  • @mmorin Could you try M-x load-library edebug.el before calling edebug-on-entry? – Tobias May 28 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. – mmorin May 29 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.