From baf64f7f4ab4a5d22e4f7cf87bd607e502bb2926 Mon Sep 17 00:00:00 2001 From: John Ogle Date: Mon, 26 Jan 2026 14:20:33 -0800 Subject: [PATCH] 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 --- home/roles/emacs/doom/config.el | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/home/roles/emacs/doom/config.el b/home/roles/emacs/doom/config.el index 4a7a535..4a1fcb8 100644 --- a/home/roles/emacs/doom/config.el +++ b/home/roles/emacs/doom/config.el @@ -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