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:
2026-01-26 14:20:33 -08:00
parent f0b6ede7ed
commit baf64f7f4a

View File

@@ -210,18 +210,25 @@
: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.
Returns nil and signals an error if the entry is not found."
(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)
(user-error "rbw: no entry found for '%s' - run: rbw add %s" alias alias)
output)))
If NO-ERROR is non-nil, return nil instead of signaling an error when
rbw is unavailable or the entry is not found."
(if (not (executable-find "rbw"))
(if no-error
nil
(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
: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-use-tools t
gptel-confirm-tool-calls 'always