diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-15 23:53:57 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-15 23:53:57 -0500 |
| commit | e749badfd974de42fe8d7cdbe2bfa4fa3e0771b2 (patch) | |
| tree | d8feeb841af8ede91f37c80d8cc2a31ec78ebc96 /tests/test-pearl-config.el | |
| parent | 8d69468b8f0a2366dd99e66763d74d059e5379b0 (diff) | |
| download | pearl-e749badfd974de42fe8d7cdbe2bfa4fa3e0771b2.tar.gz pearl-e749badfd974de42fe8d7cdbe2bfa4fa3e0771b2.zip | |
fix(api): signal missing-key as user-error with mode-aware advice
A missing API key raised a raw `error`, so it backtraced under `debug-on-error`, and the stale advice pointed at customizing `pearl-api-key`. Now `pearl--headers` signals a `user-error` and branches the advice by mode: accounts mode points at `pearl-accounts` and `pearl-switch-account`, legacy mode at `pearl-api-key` and `pearl-load-api-key-from-env`. The credential-source resolver's three failure paths become `user-error` too, since a bad credential is a config problem, not a bug.
Diffstat (limited to 'tests/test-pearl-config.el')
| -rw-r--r-- | tests/test-pearl-config.el | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/test-pearl-config.el b/tests/test-pearl-config.el index e83414c..7d6c838 100644 --- a/tests/test-pearl-config.el +++ b/tests/test-pearl-config.el @@ -40,6 +40,25 @@ (should (string-equal "lin_api_abc123" (cdr (assoc "Authorization" headers)))) (should (string-equal "application/json" (cdr (assoc "Content-Type" headers))))))) +(ert-deftest test-pearl-headers-no-key-is-user-error () + "A missing key signals a `user-error', not a raw error that backtraces." + (let ((pearl-api-key nil) (pearl-accounts nil)) + (should-error (pearl--headers) :type 'user-error))) + +(ert-deftest test-pearl-headers-no-key-legacy-advises-api-key () + "Without accounts configured, the advice names `pearl-api-key', not customize." + (let ((pearl-api-key nil) (pearl-accounts nil)) + (let ((err (should-error (pearl--headers) :type 'user-error))) + (should (string-match-p "pearl-api-key" (error-message-string err))) + (should-not (string-match-p "customize" (error-message-string err)))))) + +(ert-deftest test-pearl-headers-no-key-accounts-mode-advises-accounts () + "In accounts mode the missing-key advice points at the account setup." + (let ((pearl-api-key nil) + (pearl-accounts '(("work" :api-key-source (:literal "k") :org-file "/tmp/w.org")))) + (let ((err (should-error (pearl--headers) :type 'user-error))) + (should (string-match-p "account" (error-message-string err)))))) + ;;; pearl-toggle-debug (ert-deftest test-pearl-toggle-debug-flips-from-nil () |
