diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-21 08:03:30 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-21 08:03:30 -0400 |
| commit | 2f469404a4ef8bd0e8cdf776a5d25ba04b63febb (patch) | |
| tree | 25574906791e0e79985541c7e532c2da4e846718 /wttrin-geolocation.el | |
| parent | 275f84076988ee32d976a578d79cf0b22dea6467 (diff) | |
| download | emacs-wttrin-2f469404a4ef8bd0e8cdf776a5d25ba04b63febb.tar.gz emacs-wttrin-2f469404a4ef8bd0e8cdf776a5d25ba04b63febb.zip | |
feat: add typed error hierarchy for fetch failures
Define a wttrin-error condition with children wttrin-invalid-input, wttrin-network-error, wttrin-not-found-error, wttrin-service-error, and wttrin-parse-error, so callers branch on the class of a failure instead of matching message text.
Synchronous paths signal these directly: a nil query and an unknown geolocation provider now raise wttrin-invalid-input. The async fetch path can't signal across its callback, so it tags the error string with the class via a wttrin-error-type text property. The wttrin-error-message-type accessor reads it back, and two-arg callbacks are untouched.
Retyping the classifier also closed two gaps: a missing status and a 2xx with an empty body used to go silent or get mislabeled "Unexpected HTTP status". Both are now parse errors.
wttrin-geolocation.el now requires wttrin for the shared conditions. It's only ever loaded through wttrin, so the require is a no-op in practice and just makes the dependency explicit.
Diffstat (limited to 'wttrin-geolocation.el')
| -rw-r--r-- | wttrin-geolocation.el | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/wttrin-geolocation.el b/wttrin-geolocation.el index 03b573a..a2c31aa 100644 --- a/wttrin-geolocation.el +++ b/wttrin-geolocation.el @@ -46,6 +46,11 @@ (require 'json) (require 'url) +;; For the shared error hierarchy (`wttrin-invalid-input' et al.). This is a +;; sub-module of wttrin and is only ever loaded through it, so the require is a +;; no-op in practice; it makes the dependency explicit and keeps the condition +;; symbols defined even if this file is loaded on its own. +(require 'wttrin) (defgroup wttrin-geolocation nil "IP geolocation settings for wttrin." @@ -142,7 +147,8 @@ by pushing onto this list; the keys become valid values for "Return the provider plist for SYMBOL. Signal an error if SYMBOL is not registered." (or (cdr (assq symbol wttrin-geolocation--providers)) - (error "Unknown wttrin-geolocation provider: %S" symbol))) + (signal 'wttrin-invalid-input + (list (format "Unknown wttrin-geolocation provider: %S" symbol))))) ;;; Fetch and Detect |
