fix(emacs): make rbw password helper graceful when rbw unavailable
Add optional no-error parameter to my/get-rbw-password that returns nil instead of signaling an error when rbw isn't installed or the entry is missing. Use this for gptel API key so config loads without errors in environments without rbw configured. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -210,18 +210,25 @@
|
|||||||
:around #'my/org-caldav-add-until-property)
|
:around #'my/org-caldav-add-until-property)
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun my/get-rbw-password (alias)
|
(defun my/get-rbw-password (alias &optional no-error)
|
||||||
"Return the password for ALIAS via rbw, unlocking the vault only if needed.
|
"Return the password for ALIAS via rbw, unlocking the vault only if needed.
|
||||||
Returns nil and signals an error if the entry is not found."
|
If NO-ERROR is non-nil, return nil instead of signaling an error when
|
||||||
(let* ((cmd (format "rbw get %s 2>/dev/null" (shell-quote-argument alias)))
|
rbw is unavailable or the entry is not found."
|
||||||
(output (string-trim (shell-command-to-string cmd))))
|
(if (not (executable-find "rbw"))
|
||||||
(if (string-empty-p output)
|
(if no-error
|
||||||
(user-error "rbw: no entry found for '%s' - run: rbw add %s" alias alias)
|
nil
|
||||||
output)))
|
(user-error "rbw: not installed or not in PATH"))
|
||||||
|
(let* ((cmd (format "rbw get %s 2>/dev/null" (shell-quote-argument alias)))
|
||||||
|
(output (string-trim (shell-command-to-string cmd))))
|
||||||
|
(if (string-empty-p output)
|
||||||
|
(if no-error
|
||||||
|
nil
|
||||||
|
(user-error "rbw: no entry found for '%s' - run: rbw add %s" alias alias))
|
||||||
|
output))))
|
||||||
|
|
||||||
(after! gptel
|
(after! gptel
|
||||||
:config
|
:config
|
||||||
(setq! gptel-api-key (my/get-rbw-password "openai-api-key-chatgpt-el")
|
(setq! gptel-api-key (my/get-rbw-password "openai-api-key-chatgpt-el" t)
|
||||||
gptel-default-mode 'org-mode
|
gptel-default-mode 'org-mode
|
||||||
gptel-use-tools t
|
gptel-use-tools t
|
||||||
gptel-confirm-tool-calls 'always
|
gptel-confirm-tool-calls 'always
|
||||||
|
|||||||
Reference in New Issue
Block a user