feat(lib): introduce doom-error & error functions

This commit is contained in:
Henrik Lissner
2024-10-20 02:00:03 -04:00
parent 49f4bf6819
commit fafdb25dd8
2 changed files with 26 additions and 11 deletions

View File

@ -4,16 +4,32 @@
;;; Custom error types
(define-error 'doom-error "An unexpected Doom error")
(define-error 'doom-font-error "Could not find a font on your system" 'doom-error)
(define-error 'doom-nosync-error "Doom hasn't been initialized yet; did you remember to run 'doom sync' in the shell?" 'doom-error)
(define-error 'doom-core-error "Unexpected error in Doom's core" 'doom-error)
(define-error 'doom-context-error "Incorrect context error" 'doom-error)
(define-error 'doom-hook-error "Error in a Doom startup hook" 'doom-error)
(define-error 'doom-autoload-error "Error in Doom's autoloads file" 'doom-error)
(define-error 'doom-user-error "Error caused by user's config or system" 'doom-error)
(define-error 'doom-module-error "Error in a Doom module" 'doom-error)
(define-error 'doom-package-error "Error with packages" 'doom-error)
(define-error 'doom-profile-error "Error while processing profiles" 'doom-error)
(dolist (type '((doom-font-error "Could not find a font on your system" doom-error)
(doom-nosync-error "Doom hasn't been initialized yet; did you remember to run 'doom sync' in the shell?" doom-error)
(doom-core-error "Unexpected error in Doom's core" doom-error)
(doom-cli-error "Unexpected error in Doom's CLI" doom-error)
(doom-context-error "Incorrect context error" doom-error)
(doom-hook-error "Error in a Doom startup hook" doom-error)
(doom-autoload-error "Error in Doom's autoloads file" doom-error)
(doom-user-error "Error caused by user's config or system" doom-error)
(doom-profile-error "Error while processing profiles" doom-error)
(doom-module-error "Error in a Doom module" doom-profile-error)
(doom-source-error "Error in a Doom source" doom-profile-error)
(doom-package-error "Error with packages" doom-profile-error)))
(apply #'define-error type)
(fset (car type) (lambda (&rest data) (signal (car type) data))))
(defmacro doom-error (type &rest data)
"Signal a Doom error of TYPE with DATA.
TYPE should be a keyword of any of the known doom-*-error errors (e.g. :font,
:module, etc), or the name of any error."
`(signal ,(if (keywordp type)
`(quote
,(or (intern-soft (format "doom-%s-error" (doom-keyword-name type)))
(doom-core-error "Invalid error type" type)))
type)
(list ,@data)))
;;