diff --git a/esphome/arduino8266/toolchain.py b/esphome/arduino8266/toolchain.py index 2460940052..a7d77737e0 100644 --- a/esphome/arduino8266/toolchain.py +++ b/esphome/arduino8266/toolchain.py @@ -91,11 +91,17 @@ def run_compile(config: ConfigType, verbose: bool) -> int: return rc _print_size_summary(build_dir) - if get_idedata() is None: - _LOGGER.warning( - "Could not generate idedata from %s", - build_dir / "compile_commands.json", - ) + try: + idedata = get_idedata() + except EsphomeError as err: + # The firmware already built; idedata is a bonus artifact here + _LOGGER.warning("Could not generate idedata: %s", err) + else: + if idedata is None: + _LOGGER.warning( + "Could not generate idedata from %s", + build_dir / "compile_commands.json", + ) return 0 diff --git a/tests/unit_tests/test_arduino8266_toolchain.py b/tests/unit_tests/test_arduino8266_toolchain.py index 5f15b5b698..38ab284068 100644 --- a/tests/unit_tests/test_arduino8266_toolchain.py +++ b/tests/unit_tests/test_arduino8266_toolchain.py @@ -337,3 +337,24 @@ def test_warn_ignored_platformio_options(caplog: pytest.LogCaptureFixture) -> No assert "native 'arduino' toolchain" in caplog.text assert "lib_ignore" not in caplog.text assert "upload_speed" not in caplog.text + + +def test_run_compile_idedata_error_does_not_fail_build( + tmp_path: Path, caplog: pytest.LogCaptureFixture +) -> None: + """An unusable compile DB after a successful build warns, never fails.""" + with ( + patch.object(framework, "check_and_install", return_value=_paths(tmp_path)), + patch.object(framework, "get_build_env", return_value={}), + patch("esphome.build_gen.arduino8266.write_project"), + patch.object(toolchain.subprocess, "run", return_value=MagicMock(returncode=0)), + patch.object(toolchain, "_write_compile_commands"), + patch.object(toolchain, "_print_size_summary"), + patch.object( + toolchain, + "get_idedata", + side_effect=EsphomeError("compile database is unusable"), + ), + ): + assert toolchain.run_compile({CONF_ESPHOME: {}}, verbose=False) == 0 + assert "Could not generate idedata: compile database is unusable" in caplog.text