From 8cf1232a6a2a21a952faed501490184348096b52 Mon Sep 17 00:00:00 2001 From: jordansilly77-stack Date: Mon, 22 Jun 2026 10:34:56 +0800 Subject: [PATCH] Stop analysis when parse errors occur --- source/fab/steps/analyse.py | 9 +++------ tests/unit_tests/steps/test_analyse.py | 22 +++++++++------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/source/fab/steps/analyse.py b/source/fab/steps/analyse.py index 4f2ad4ff..346485d2 100644 --- a/source/fab/steps/analyse.py +++ b/source/fab/steps/analyse.py @@ -46,7 +46,7 @@ from fab.parse import AnalysedFile, EmptySourceFile from fab.parse.c import AnalysedC, CAnalyser from fab.parse.fortran import AnalysedFortran, FortranParserWorkaround, FortranAnalyser -from fab.steps import run_mp, step +from fab.steps import check_for_errors, run_mp, step from fab.util import TimerLogger, by_type logger = logging.getLogger(__name__) @@ -262,12 +262,9 @@ def _parse_files(config, files: list[Path], fortran_analyser, c_analyser) -> set c_results = run_mp(config, items=c_files, func=c_analyser.run, no_multiprocessing=no_multiprocessing) c_analyses, c_artefacts = zip(*c_results) if c_results else (tuple(), tuple()) - # Check for parse errors but don't fail. The failed files might not be required. + # Check for parse errors before continuing to dependency analysis. analyses = fortran_analyses + c_analyses - exceptions = list(by_type(analyses, Exception)) - if exceptions: - err_str = '\n\n'.join(map(str, exceptions)) - print(f"\nThere were {len(exceptions)} analysis errors:\n\n{err_str}\n\n", file=sys.stderr) + check_for_errors(analyses, caller_label="analyse") # record the artefacts as being current artefacts = by_type(fortran_artefacts + c_artefacts, Path) diff --git a/tests/unit_tests/steps/test_analyse.py b/tests/unit_tests/steps/test_analyse.py index 3a1536eb..4426619e 100644 --- a/tests/unit_tests/steps/test_analyse.py +++ b/tests/unit_tests/steps/test_analyse.py @@ -153,26 +153,22 @@ def test_exceptions(self, tmp_path: Path, stub_tool_repository: ToolRepository, monkeypatch) -> None: """ - Tests exceptions thrown from processing do not halt build. - - ToDo: Do we want this? Shouldn't exceptions stop build? + Tests exceptions thrown from processing halt the build. ToDo: Messing with "private" methods. """ - def raises(*args, **kwargs): - raise Exception("foo") + def analyse_error(*args, **kwargs): + return [(Exception("foo"), None)] - # The warning "deprecated 'DEPENDS ON:' comment found in fortran - # code" is in "def _parse_files" in "source/steps/analyse.py" config = BuildConfig('proj', ToolBox(), fab_workspace=tmp_path) + fortran_analyser = Mock(depends_on_comment_found=False) + c_analyser = Mock() - monkeypatch.setattr('fab.steps.run_mp', raises) - with warns(UserWarning, match="deprecated 'DEPENDS ON:'"): - # the exception should be suppressed (and logged) and this step - # should run to completion + monkeypatch.setattr('fab.steps.analyse.run_mp', analyse_error) + with raises(RuntimeError, match="foo"): _parse_files(config, files=[], - fortran_analyser=Mock(), - c_analyser=Mock()) + fortran_analyser=fortran_analyser, + c_analyser=c_analyser) class TestAddManualResults: