From e13aa8b775b4082526e24849f31d4d4d9688866f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 26 Aug 2026 00:46:45 -0500 Subject: [PATCH] Read the pch sidecars defensively in the generic flow too --- esphome/build_helpers/pch.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/esphome/build_helpers/pch.py b/esphome/build_helpers/pch.py index f453ff31cd..fe414a94ca 100644 --- a/esphome/build_helpers/pch.py +++ b/esphome/build_helpers/pch.py @@ -266,6 +266,14 @@ def _log_pch_in_use() -> None: ) +def _read_stamp(path: Path) -> str: + """A corrupt sidecar must read as stale, not kill the pch forever.""" + try: + return path.read_text(encoding="utf-8").strip() + except (OSError, UnicodeDecodeError): + return "" + + def discard_pch(build_dir: Path) -> None: """Remove the pch sidecars so a stale .gch is never consumed. @@ -330,18 +338,11 @@ def prepare_pch( ) discard_pch(build_dir) return - if ( - gch.is_file() - and sum_path.is_file() - and sum_path.read_text(encoding="utf-8").strip() == checksum - ): + if gch.is_file() and _read_stamp(sum_path) == checksum: _log_pch_in_use() return failed_marker = Path(f"{gch}.failed") - if ( - failed_marker.is_file() - and failed_marker.read_text(encoding="utf-8").strip() == checksum - ): + if _read_stamp(failed_marker) == checksum: _LOGGER.info( "Precompiled header disabled after an earlier failure; delete %s to retry", failed_marker,