refactor(cli): better error for missing profiles.el

Only appears if a profile was requested and no profile file was found.
This commit is contained in:
Henrik Lissner
2022-07-29 12:32:35 +02:00
parent 068966a4cd
commit 491f49cfe5

View File

@@ -47,16 +47,22 @@
(when profile (when profile
(with-temp-buffer (with-temp-buffer
(let ((coding-system-for-read 'utf-8-auto) (let ((coding-system-for-read 'utf-8-auto)
(profile-file (expand-file-name "profiles.el" user-emacs-directory))) (profiles-file (expand-file-name "profiles.el" user-emacs-directory)))
(insert-file-contents profile-file)
(condition-case e (condition-case e
(progn
(insert-file-contents profiles-file)
(dolist (var (or (cdr (assq (intern profile) (read (current-buffer)))) (dolist (var (or (cdr (assq (intern profile) (read (current-buffer))))
(progn (message "No %S profile found" profile) (progn (message "No %S profile found" profile)
(kill-emacs 3)))) (kill-emacs 3))))
(if (eq (car var) 'env) (if (eq (car var) 'env)
(dolist (env (cdr var)) (setenv (car env) (cdr env))) (dolist (env (cdr var)) (setenv (car env) (cdr env)))
(set (car var) (cdr var)))) (set (car var) (cdr var)))))
(end-of-file (signal 'end-of-file (list profile-file))) (file-missing
(message "No $EMACSDIR/%s file to look up %S in."
(file-name-nondirectory profiles-file)
profile)
(kill-emacs 3))
(end-of-file (signal 'end-of-file (list profiles-file)))
(error (error "Parser error in profiles.el: %s" (error-message-string e)))))))) (error (error "Parser error in profiles.el: %s" (error-message-string e))))))))
;; HACK Load `cl' and site files manually to prevent polluting logs and stdout ;; HACK Load `cl' and site files manually to prevent polluting logs and stdout