diff options
| author | Craig Jennings <c@cjennings.net> | 2026-02-20 07:06:47 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-02-20 07:06:47 -0600 |
| commit | 30fe3ab230a66f98dd8ece253bf79c61c2fbf6e1 (patch) | |
| tree | 39221778a045dd0b8b4a55dea8fcce8945d5d032 /wttrin.el | |
| parent | 332b51d4971299690c1f8ac5cce5f061e1071e56 (diff) | |
| download | emacs-wttrin-30fe3ab230a66f98dd8ece253bf79c61c2fbf6e1.tar.gz emacs-wttrin-30fe3ab230a66f98dd8ece253bf79c61c2fbf6e1.zip | |
fix: mode-line: validate API response before updating display
Reject empty or malformed wttr.in responses to prevent blank icon and
tooltip. Fix tooltip lambda to treat empty string as falsy. Add debug
logging for nil-location and invalid-response paths.
Diffstat (limited to 'wttrin.el')
| -rw-r--r-- | wttrin.el | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -476,12 +476,22 @@ This creates headroom to avoid frequent cleanups." ;;; Mode-line weather display +(defun wttrin--mode-line-valid-response-p (weather-string) + "Return non-nil if WEATHER-STRING looks like a valid mode-line response. +Expected format: \"Location: emoji temp conditions\", +e.g., \"Paris: ☀️ +61°F Clear\"." + (and (stringp weather-string) + (not (string-empty-p weather-string)) + (string-match-p ":" weather-string))) + (defun wttrin--mode-line-fetch-weather () "Fetch weather for favorite location and update mode-line display. Uses wttr.in custom format for concise weather with emoji." (when (featurep 'wttrin-debug) (wttrin--debug-log "mode-line-fetch: Starting fetch for %s" wttrin-favorite-location)) - (when wttrin-favorite-location + (if (not wttrin-favorite-location) + (when (featurep 'wttrin-debug) + (wttrin--debug-log "mode-line-fetch: No favorite location set, skipping")) (let* ((location wttrin-favorite-location) ;; Custom format: location + emoji + temp + conditions ;; %l=location, %c=weather emoji, %t=temp, %C=conditions @@ -501,7 +511,10 @@ Uses wttr.in custom format for concise weather with emoji." (let ((trimmed-data (string-trim data))) (when (featurep 'wttrin-debug) (wttrin--debug-log "mode-line-fetch: Received data = %S" trimmed-data)) - (wttrin--mode-line-update-display trimmed-data)) + (if (wttrin--mode-line-valid-response-p trimmed-data) + (wttrin--mode-line-update-display trimmed-data) + (when (featurep 'wttrin-debug) + (wttrin--debug-log "mode-line-fetch: Invalid response, keeping previous display")))) (when (featurep 'wttrin-debug) (wttrin--debug-log "mode-line-fetch: No data received (network error)")))))))) @@ -532,9 +545,11 @@ e.g., \"Paris: ☀️ +61°F Clear\"." (setq wttrin-mode-line-string (propertize (concat " " emoji-with-font) 'help-echo (lambda (_window _object _pos) - (or wttrin--mode-line-tooltip-data + (let ((tip wttrin--mode-line-tooltip-data)) + (if (and tip (not (string-empty-p tip))) + tip (format "Weather for %s\nClick to refresh" - wttrin-favorite-location))) + wttrin-favorite-location)))) 'mouse-face 'mode-line-highlight 'local-map wttrin--mode-line-map))) (force-mode-line-update t) |
