diff --git a/esphome/components/esp8266/__init__.py b/esphome/components/esp8266/__init__.py index 4084893e7c..a5f540d7be 100644 --- a/esphome/components/esp8266/__init__.py +++ b/esphome/components/esp8266/__init__.py @@ -138,7 +138,12 @@ def _format_framework_arduino_version(ver: cv.Version) -> str: # version bump cannot drift between the two paths. from esphome.arduino8266.framework import framework_package_version - return f"~{framework_package_version(ver)}" + try: + return f"~{framework_package_version(ver)}" + except EsphomeError as err: + # Anchor the 4.x rejection to the framework version line instead of + # aborting with a bare traceback-level error + raise cv.Invalid(str(err)) from err # NOTE: Keep this in mind when updating the recommended version: diff --git a/tests/unit_tests/test_arduino8266_framework.py b/tests/unit_tests/test_arduino8266_framework.py index c69f802c9e..56d89cc37d 100644 --- a/tests/unit_tests/test_arduino8266_framework.py +++ b/tests/unit_tests/test_arduino8266_framework.py @@ -38,7 +38,8 @@ def test_format_framework_arduino_version_pins_all_series() -> None: assert fmt(cv.Version(2, 6, 2)) == "~2.20602.0" assert fmt(cv.Version(2, 7, 4)) == "~3.20704.0" assert fmt(cv.Version(3, 1, 2)) == "~3.30102.0" - with pytest.raises(EsphomeError, match="not supported yet"): + # Anchored to the framework version line, not a bare EsphomeError + with pytest.raises(cv.Invalid, match="not supported yet"): fmt(cv.Version(4, 0, 0)) @@ -110,7 +111,7 @@ def test_ccache_env(tmp_path: Path) -> None: assert framework.ccache_env() == {} with ( patch.object(framework, "ccache_path", return_value="/usr/bin/ccache"), - patch.dict(os.environ, {"CCACHE_NOHASHDIR": "false"}), + patch.dict(os.environ, {"CCACHE_NOHASHDIR": "false"}, clear=True), ): env = framework.ccache_env() # User-set values are respected; the rest get defaults