summaryrefslogtreecommitdiff
path: root/wttrin.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-11-08 11:53:02 -0600
committerCraig Jennings <c@cjennings.net>2025-11-08 11:53:02 -0600
commit1f40ef408641680c951a65b72be240d9b7729d8e (patch)
tree083ae2d5ecf73134311233152f9dacc3f125fb77 /wttrin.el
parentb44277b019ac64ffeacde0214cd3c9cd18014ba9 (diff)
downloademacs-wttrin-1f40ef408641680c951a65b72be240d9b7729d8e.tar.gz
emacs-wttrin-1f40ef408641680c951a65b72be240d9b7729d8e.zip
feat: debug: add comprehensive debug logging and integration tests
Enhanced wttrin-debug.el: - Added wttrin--debug-log() function for timestamped logging - Added wttrin--debug-clear-log() to clear log - Added wttrin--debug-show-log() to display log in buffer - Debug log structure: list of (timestamp . message) pairs Added debug logging to key functions in wttrin.el: - wttrin--fetch-url: Logs start, success (bytes), and errors - wttrin--mode-line-fetch-weather: Logs start, URL, data received - wttrin--mode-line-update-display: Logs display update, emoji extraction Created comprehensive integration tests: - test-wttrin-integration-with-debug.el (5 tests, 3 passing) - Tests fetch, mode-line display, error handling with debug logging - Includes mocked network calls to avoid external dependencies - Example debug output shows complete flow: [wttrin-debug 11:51:46.490] mode-line-fetch: Starting fetch for Berkeley, CA [wttrin-debug 11:51:46.490] mode-line-fetch: Received data = "Berkeley, CA: ☀️ +62°F Clear" [wttrin-debug 11:51:46.490] mode-line-display: Extracted emoji = "☀", font = Noto Color Emoji [wttrin-debug 11:51:46.490] mode-line-display: Complete. mode-line-string set = YES Added test fixtures: - tests/fixtures/test-init.el: Minimal config with debug enabled - tests/README-DEBUG-TESTS.md: Documentation for using debug features Usage: (setq wttrin-debug t) ; Before loading wttrin (require 'wttrin) M-x wttrin--debug-show-log ; View all logged events This provides complete visibility into wttrin's operation for troubleshooting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'wttrin.el')
-rw-r--r--wttrin.el39
1 files changed, 28 insertions, 11 deletions
diff --git a/wttrin.el b/wttrin.el
index 1ea8e11..d3f507c 100644
--- a/wttrin.el
+++ b/wttrin.el
@@ -209,6 +209,8 @@ This is a pure function with no side effects, suitable for testing."
"Asynchronously fetch URL and call CALLBACK with decoded response.
CALLBACK is called with the weather data string when ready, or nil on error.
Handles header skipping, UTF-8 decoding, and error handling automatically."
+ (when (featurep 'wttrin-debug)
+ (wttrin--debug-log "wttrin--fetch-url: Starting fetch for URL: %s" url))
(let ((url-request-extra-headers (list wttrin-default-languages))
(url-user-agent "curl"))
(url-retrieve
@@ -218,6 +220,9 @@ Handles header skipping, UTF-8 decoding, and error handling automatically."
(condition-case err
(if (plist-get status :error)
(progn
+ (when (featurep 'wttrin-debug)
+ (wttrin--debug-log "wttrin--fetch-url: Network error - %s"
+ (cdr (plist-get status :error))))
(message "wttrin: Network error - %s" (cdr (plist-get status :error)))
(setq data nil))
(unwind-protect
@@ -227,9 +232,15 @@ Handles header skipping, UTF-8 decoding, and error handling automatically."
(re-search-forward "\r?\n\r?\n" nil t)
(setq data (decode-coding-string
(buffer-substring-no-properties (point) (point-max))
- 'utf-8)))
+ 'utf-8))
+ (when (featurep 'wttrin-debug)
+ (wttrin--debug-log "wttrin--fetch-url: Successfully fetched %d bytes"
+ (length data))))
(kill-buffer (current-buffer))))
(error
+ (when (featurep 'wttrin-debug)
+ (wttrin--debug-log "wttrin--fetch-url: Error processing response - %s"
+ (error-message-string err)))
(message "wttrin: Error processing response - %s" (error-message-string err))
(setq data nil)))
(funcall callback data))))))
@@ -430,7 +441,7 @@ CALLBACK is called with the weather data string when ready, or nil on error."
"Fetch weather for favorite location and update mode-line display.
Uses wttr.in custom format for concise weather with emoji."
(when (featurep 'wttrin-debug)
- (message "wttrin mode-line: Fetching weather for %s" wttrin-mode-line-favorite-location))
+ (wttrin--debug-log "mode-line-fetch: Starting fetch for %s" wttrin-mode-line-favorite-location))
(when wttrin-mode-line-favorite-location
(let* ((location wttrin-mode-line-favorite-location)
;; Custom format: location + emoji + temp + conditions
@@ -443,22 +454,24 @@ Uses wttr.in custom format for concise weather with emoji."
(url-hexify-string location)
format-params)))
(when (featurep 'wttrin-debug)
- (message "wttrin mode-line: URL = %s" url))
+ (wttrin--debug-log "mode-line-fetch: URL = %s" url))
(wttrin--fetch-url
url
(lambda (data)
- (when data
- (let ((trimmed-data (string-trim data)))
- (when (featurep 'wttrin-debug)
- (message "wttrin mode-line: Received data = %S" trimmed-data))
- (wttrin--mode-line-update-display trimmed-data))))))))
+ (if data
+ (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))
+ (when (featurep 'wttrin-debug)
+ (wttrin--debug-log "mode-line-fetch: No data received (network error)"))))))))
(defun wttrin--mode-line-update-display (weather-string)
"Update mode-line display with WEATHER-STRING.
Extracts emoji for mode-line, stores full info for tooltip.
WEATHER-STRING format: \"Location: emoji temp conditions\" (e.g., \"Paris: ☀️ +61°F Clear\")."
(when (featurep 'wttrin-debug)
- (message "wttrin mode-line: Updating display with: %S" weather-string))
+ (wttrin--debug-log "mode-line-display: Updating display with: %S" weather-string))
;; Store full weather info for tooltip
(setq wttrin--mode-line-tooltip-data weather-string)
;; Extract just the emoji for mode-line display
@@ -473,6 +486,9 @@ WEATHER-STRING format: \"Location: emoji temp conditions\" (e.g., \"Paris: ☀
'face (list :family wttrin-mode-line-emoji-font
:height 1.0))
emoji)))
+ (when (featurep 'wttrin-debug)
+ (wttrin--debug-log "mode-line-display: Extracted emoji = %S, font = %s"
+ emoji wttrin-mode-line-emoji-font))
(setq wttrin-mode-line-string
(propertize (concat " " emoji-with-font)
'help-echo (lambda (_window _object _pos)
@@ -483,8 +499,9 @@ WEATHER-STRING format: \"Location: emoji temp conditions\" (e.g., \"Paris: ☀
'local-map wttrin--mode-line-map)))
(force-mode-line-update t)
(when (featurep 'wttrin-debug)
- (message "wttrin mode-line: Display updated, mode-line-string = %S, tooltip = %S"
- wttrin-mode-line-string wttrin--mode-line-tooltip-data)))
+ (wttrin--debug-log "mode-line-display: Complete. mode-line-string set = %s, tooltip = %S"
+ (if wttrin-mode-line-string "YES" "NO")
+ wttrin--mode-line-tooltip-data)))
(defun wttrin-mode-line-click ()
"Handle left-click on mode-line weather widget.