core-dotspacemacs: Make call-func macro safer

Catch errors in executed function and signal them to the user in the
spacemacs buffer. We don't want loading to silently fail because there
is a problem in dotspacemacs/user-config for example.
This commit is contained in:
justbur 2015-10-12 09:07:48 -04:00 committed by syl20bnr
parent b44d27aad4
commit 8b5428d320

View file

@ -401,10 +401,18 @@ error recovery."
(defmacro dotspacemacs|call-func (func &optional msg) (defmacro dotspacemacs|call-func (func &optional msg)
"Call the function from the dotfile only if it is bound. "Call the function from the dotfile only if it is bound.
If MSG is not nil then display a message in `*Messages'." If MSG is not nil then display a message in `*Messages'. Errors
are caught and signalled to user in spacemacs buffer."
`(progn `(progn
(when ,msg (spacemacs-buffer/message ,msg)) (when ,msg (spacemacs-buffer/message ,msg))
(if (fboundp ',func) (,func)))) (when (fboundp ',func)
(condition-case-unless-debug err
(,func)
(error (spacemacs-buffer/append
(format "Error in %s: %s\n"
',(symbol-name func)
(error-message-string err))
t))))))
(defun dotspacemacs//test-dotspacemacs/layers () (defun dotspacemacs//test-dotspacemacs/layers ()
"Tests for `dotspacemacs/layers'" "Tests for `dotspacemacs/layers'"