I have a package that invokes some user-defined code that can be error-prone. For the most part, I'd like to respect the user's choices for handling errors, e.g. debug-on-error
. However, due to some layers of indirection and the use of closures, it can be hard to understand the context of the error from the backtrace alone because original function names are erased, so I'd like to enhance the error message to add some useful context information. How can this be done?
I've tried the solution in Rethrowing an error in Emacs Lisp, however, this loses the valuable backtrace information.
I also tried setting a custom debugger: Get backtrace from error programmatically but this interferes with the standard debugger and may not respect user's debugger choices.