Guard against empty or unparseable WeatherUnderground responses (#154) - #329
Open
7onnie wants to merge 1 commit into
Open
Guard against empty or unparseable WeatherUnderground responses (#154)#3297onnie wants to merge 1 commit into
7onnie wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With the WeatherUnderground API selected, the plugin intermittently logs
SyntaxError: Unexpected end of JSON inputand the update cycle silently reports an empty weather object instead of skipping the failed poll.Root cause
apis/weatherunderground.jsrelies on axios to parse the response body as JSON. When WeatherUnderground returns a truncated or otherwise unparseable 200 body, axios'stransformResponsesilently swallows theJSON.parsefailure and leavesresponse.dataas a non-empty string. The old guardif (response.data)is truthy for that string, so the code proceeds intoparseReport(...)on a string, throws internally, returns{}and ends up callingcallback(null, { report: {} })— a bogus successful empty update.Fix
Tighten the guard to require an actual parsed object:
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:callback(null, {report:{}})(bogus success)callback(error), cycle skippedcallback(error)node --checkpasses (repo has no build/lint/test scripts). No secrets in the diff.Notes
'', falsy) — the new behaviour specifically covers the truncated/unparseable-but-non-empty case.Fixes #154