From fafdb25dd8a6ecd21ba82ffc0e92be3816d063ba Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 20 Oct 2024 02:00:03 -0400 Subject: [PATCH] feat(lib): introduce doom-error & error functions --- lisp/doom-cli-lib.el | 1 - lisp/doom-lib.el | 36 ++++++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lisp/doom-cli-lib.el b/lisp/doom-cli-lib.el index 4d447fec6..43d180000 100644 --- a/lisp/doom-cli-lib.el +++ b/lisp/doom-cli-lib.el @@ -228,7 +228,6 @@ the return value of the executed CLI." ;; ;;; Errors -(define-error 'doom-cli-error "There was an unexpected error" 'doom-error) (define-error 'doom-cli-definition-error "Invalid CLI definition" 'doom-cli-error) (define-error 'doom-cli-autoload-error "Failed to autoload deferred command" 'doom-cli-error) (define-error 'doom-cli-invalid-prefix-error "Prefix has no defined commands" 'doom-cli-error) diff --git a/lisp/doom-lib.el b/lisp/doom-lib.el index 48ec296eb..8644884b3 100644 --- a/lisp/doom-lib.el +++ b/lisp/doom-lib.el @@ -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))) ;;