diff --git a/src/mlx/warnings/regex_checker.py b/src/mlx/warnings/regex_checker.py index 6ddff0e7..cb833f6b 100644 --- a/src/mlx/warnings/regex_checker.py +++ b/src/mlx/warnings/regex_checker.py @@ -73,7 +73,11 @@ def add_code_quality_finding(self, match): if name.startswith("path"): path = Path(result) if path.is_absolute(): - path = path.relative_to(Path.cwd()) + try: + path = path.relative_to(Path.cwd()) + except ValueError as err: + raise ValueError("Failed to convert abolute path to relative path for Code Quality report: " + f"{err}") from err finding["location"]["path"] = str(path) break for name, result in groups.items(): diff --git a/tests/test_integration.py b/tests/test_integration.py index 95267c8a..0dad2eb1 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -316,6 +316,20 @@ def test_code_quality(self, path_cwd_mock): self.assertEqual(2, retval) self.assertTrue(filecmp.cmp(out_file, ref_file), '{} differs from {}'.format(out_file, ref_file)) + def test_code_quality_abspath_failure(self): + filename = 'code_quality.json' + out_file = str(TEST_OUT_DIR / filename) + with self.assertRaises(ValueError) as c_m: + warnings_wrapper([ + '--code-quality', out_file, + '--config', 'tests/test_in/config_example.json', + 'tests/test_in/mixed_warnings.txt', + ]) + self.assertTrue(str(c_m.exception).startswith( + "Failed to convert abolute path to relative path for Code Quality report: " + "'/home/user/myproject/helper/SimpleTimer.h'") + ) + def test_cq_description_format_missing_envvar(self): os.environ['FIRST_ENVVAR'] = 'envvar_value' filename = 'code_quality_format.json'