MagicMirrorOrg/MagicMirror · error · Error

Invalid current weather data

Error message

Invalid current weather data

What it means

#handleResponse switches on this.config.type and validates the fetched data before building the weather object. For "current" it requires data.properties; a missing properties object means the latest-observation payload is unusable, so it throws "Invalid current weather data".

Solutions

  1. Log the raw data around the throw to read any NWS error message in the body.
  2. The provider re-fetches on its interval — wait for the station to resume reporting; if persistent, the station is dead.
  3. Choose a nearby grid point/station with active reporting, or switch type to "forecast".
  4. Update MagicMirror if NWS changed the observation schema; check the repo for recent weathergov fixes.

Example fix

// before
case "current":
  if (!data.properties) {
    throw new Error("Invalid current weather data");
  }
// after — fall back to skipping this cycle instead of throwing
if (!data.properties) {
  Log.error("[weathergov] No properties in current observation; skipping");
  return;
}
Defensive patterns

Strategy: type-guard

Validate before calling

const r = await fetch(`${stationId}/observations/latest`, { headers: { "User-Agent": "MagicMirror" } });
const j = await r.json();
if (!j?.properties) console.warn("Station latest observation unavailable — station may be offline");

Type guard

function hasCurrentObservation(d) {
  return !!d && typeof d === "object" && !!d.properties
    && typeof d.properties.temperature === "object";
}

Try / catch

try {
  await provider.initialize();
} catch (err) {
  if (err.message === "Invalid current weather data") {
    Log.warn("weathergov: station observation unusable — will retry next cycle");
    renderPlaceholder(); // skip this cycle rather than crash the module
  } else { throw err; }
}

Prevention

When it happens

Trigger: The /observations/latest endpoint returns JSON without a properties field: an API error envelope, an empty/deprecated station observation, or an NWS response shape change.

Common situations: Station temporarily not reporting (properties absent while station is offline); stale observation removed by NWS; rate-limit or error JSON returned with a 200/ok status from a cache layer.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of MagicMirrorOrg/MagicMirror@4b4a59534f (2026-08-31). Data as JSON: /api/errors/98d73061aa72d598. Report an issue: GitHub.

Appendix: source

Thrown at defaultmodules/weather/providers/weathergov.js:239

				}
			}
		});

		this.fetcher.on("error", (errorInfo) => {
			if (this.onErrorCallback) {
				this.onErrorCallback(errorInfo);
			}
		});
	}

	#handleResponse (data) {
		try {
			let weatherData;

			switch (this.config.type) {
				case "current":
					if (!data.properties) {
						throw new Error("Invalid current weather data");
					}
					weatherData = this.#generateWeatherObjectFromCurrentWeather(data.properties);
					break;
				case "forecast":
				case "daily":
					if (!data.properties || !data.properties.periods) {
						throw new Error("Invalid forecast data");
					}
					weatherData = this.#generateWeatherObjectsFromForecast(data.properties.periods);
					break;
				case "hourly":
					if (!data.properties || !data.properties.periods) {
						throw new Error("Invalid hourly data");
					}
					weatherData = this.#generateWeatherObjectsFromHourly(data.properties.periods);
					break;
				default:
					throw new Error(`Unknown weather type: ${this.config.type}`);

View on GitHub (pinned to 4b4a59534f)