Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
Last active August 25, 2023 02:31
Show Gist options
  • Save jdtsmith/1fbcacfe677d74bbe510aec80ac0050c to your computer and use it in GitHub Desktop.
Save jdtsmith/1fbcacfe677d74bbe510aec80ac0050c to your computer and use it in GitHub Desktop.
Elisp: get stack trace for functions with suppressed errors (filter functions, post command hooks, etc.)
;;;; Power debugging
(defun my/reraise-error (func &rest args)
"Call function FUNC with ARGS and re-raise any error which occurs.
Useful for debugging post-command hooks and filter functions, which
normally have their errors suppressed."
(condition-case err
(apply func args)
((debug error) (signal (car err) (cdr err)))))
(defun toggle-debug-on-hidden-errors (func)
"Toggle hidden error debugging for function FUNC."
(interactive "a")
(cond
((advice-member-p #'my/reraise-error func)
(advice-remove func #'my/reraise-error)
(message "Debug on hidden errors disabled for %s" func))
(t
(advice-add func :around #'my/reraise-error)
(message "Debug on hidden errors enabled for %s" func))))
@minad
Copy link

minad commented Feb 9, 2023

See also https://github.com/minad/vertico#debugging-vertico. The Vertico post-command-hook does not have any subtle bugs but some completion tables may have them. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment