mirror of
https://github.com/esphome/esphome.git
synced 2026-08-24 07:06:20 +00:00
Check the JSON shape explicitly instead of AttributeError control flow
This commit is contained in:
+4
-4
@@ -337,14 +337,14 @@ def copy_src_tree():
|
||||
else:
|
||||
try:
|
||||
existing = json.loads(build_info_json_path.read_text(encoding="utf-8"))
|
||||
if (
|
||||
if not isinstance(existing, dict) or (
|
||||
existing.get("config_hash") != config_hash
|
||||
or existing.get("esphome_version") != __version__
|
||||
):
|
||||
# Valid JSON that is not an object (truncated or
|
||||
# hand-edited) is stale like every other damage case
|
||||
sources_changed = True
|
||||
except (json.JSONDecodeError, AttributeError, KeyError, OSError):
|
||||
# AttributeError: valid JSON that is not an object (truncated
|
||||
# or hand-edited) has no .get; treat it as stale like the rest
|
||||
except (json.JSONDecodeError, OSError):
|
||||
sources_changed = True
|
||||
|
||||
# Write build_info header and JSON metadata
|
||||
|
||||
@@ -2232,7 +2232,7 @@ def test_copy_src_tree_handles_non_dict_build_info_json(
|
||||
build_path = tmp_path / "build"
|
||||
build_path.mkdir()
|
||||
|
||||
# Create invalid build_info.json
|
||||
# Valid JSON that is not an object: no .get, must read as stale
|
||||
build_info_json_path = build_path / "build_info.json"
|
||||
build_info_json_path.write_text("[]")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user