fix(lib): resolve relative paths in doom-load errors

And don't forward file-missing errors, as this would convolute them.
This commit is contained in:
Henrik Lissner 2022-09-15 19:13:16 +02:00
parent 41051f4761
commit d552dbc878
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -135,27 +135,20 @@ If NOERROR, don't throw an error if PATH doesn't exist."
(doom-log "load: %s %s" (abbreviate-file-name path) noerror)
(condition-case-unless-debug e
(load path noerror 'nomessage)
((doom-error file-missing)
(doom-error
(signal (car e) (cdr e)))
(error
(unless (file-name-absolute-p path)
(when-let (newpath (locate-file path load-path))
(setq path newpath)))
(cl-destructuring-bind (err . dir)
(cond ((not path)
(cons 'error path))
((not (featurep 'doom))
(cons 'error (file-name-directory path)))
(setq path (locate-file path load-path (get-load-suffixes)))
(signal (cond ((not (and path (featurep 'doom)))
'error)
((file-in-directory-p path (expand-file-name "cli" doom-core-dir))
(cons 'doom-cli-error doom-emacs-dir))
'doom-cli-error)
((file-in-directory-p path doom-core-dir)
(cons 'doom-core-error doom-emacs-dir))
'doom-core-error)
((file-in-directory-p path doom-user-dir)
(cons 'doom-user-error doom-user-dir))
((cons 'doom-module-error doom-emacs-dir)))
(signal err (list (unless (equal path dir)
(file-relative-name (or path "") dir))
e))))))
'doom-user-error)
('doom-module-error))
(list path e)))))
(defun doom-require (feature &optional filename noerror)
"Like `require', but handles and enhances Doom errors.