Skip to content

Guard against empty or unparseable WeatherUnderground responses (#154) - #329

Open
7onnie wants to merge 1 commit into
naofireblade:masterfrom
7onnie:fix/weatherunderground-empty-response-guard
Open

Guard against empty or unparseable WeatherUnderground responses (#154)#329
7onnie wants to merge 1 commit into
naofireblade:masterfrom
7onnie:fix/weatherunderground-empty-response-guard

Conversation

@7onnie

@7onnie 7onnie commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Problem

With the WeatherUnderground API selected, the plugin intermittently logs SyntaxError: Unexpected end of JSON input and the update cycle silently reports an empty weather object instead of skipping the failed poll.

Root cause

apis/weatherunderground.js relies on axios to parse the response body as JSON. When WeatherUnderground returns a truncated or otherwise unparseable 200 body, axios's transformResponse silently swallows the JSON.parse failure and leaves response.data as a non-empty string. The old guard if (response.data) is truthy for that string, so the code proceeds into parseReport(...) on a string, throws internally, returns {} and ends up calling callback(null, { report: {} }) — a bogus successful empty update.

Fix

Tighten the guard to require an actual parsed object:

if (response.data && typeof response.data === 'object') { ... }
else { /* report a clear error and skip this cycle */ }

Unparseable/truncated responses now take the error branch. The caller (index.js) already gates on !error, so the cycle is skipped cleanly with no characteristic writes — no stale or zeroed values.

Validation (no hardware required)

Drove the real WundergroundAPI.update() against mock HTTP servers:

Response Before After
valid 200 JSON normal report normal report (unchanged)
truncated 200 body callback(null, {report:{}}) (bogus success) callback(error), cycle skipped
empty 200 body already handled callback(error)

node --check passes (repo has no build/lint/test scripts). No secrets in the diff.

Notes

  • Empty bodies were already handled (axios leaves an empty 200 as '', falsy) — the new behaviour specifically covers the truncated/unparseable-but-non-empty case.
  • Likely the same root cause behind API- Fehler Weather Underground #310.

Fixes #154

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SyntaxError: Unexpected end of JSON input (WeatherUnderground)

1 participant