From 45617376efddc61898d459a394ef8596ee42b23d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 22 Aug 2026 22:40:48 -0500 Subject: [PATCH] Catch only EsphomeError; read_file wraps the decode error too --- esphome/helpers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/helpers.py b/esphome/helpers.py index 485b1f5b41..ecb6219bdc 100644 --- a/esphome/helpers.py +++ b/esphome/helpers.py @@ -562,7 +562,8 @@ def write_file_if_changed(path: Path, text: str) -> bool: if path.is_file(): try: src_content = read_file(path) - except (EsphomeError, UnicodeDecodeError) as err: + except EsphomeError as err: + # read_file wraps OSError and UnicodeDecodeError alike # A damaged existing file (unreadable, non-UTF-8) must be # replaced, not abort the regeneration that would fix it _LOGGER.warning("Replacing damaged file %s: %s", path, err)