Skip to content

Commit 483b391

Browse files
committed
fix: handle the file not error gracefully
1 parent 8503ef5 commit 483b391

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/commitlint/cli.py

+4
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ def main() -> None:
228228
console.error(f"{ex}")
229229
sys.exit(1)
230230

231+
except FileNotFoundError as ex:
232+
console.error(f"{ex}")
233+
sys.exit(1)
234+
231235

232236
if __name__ == "__main__":
233237
main() # pragma: no cover

tests/test_cli.py

+16
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,22 @@ def test__main__sets_config_for_verbose(
383383
main()
384384
assert config.verbose is True
385385

386+
@patch(
387+
"commitlint.cli.get_args",
388+
return_value=MagicMock(
389+
file="path/to/non_existent_file.txt", skip_detail=False, quiet=False
390+
),
391+
)
392+
def test__main__with_missing_file(
393+
self, _mock_get_args, _mock_output_error, mock_output_success
394+
):
395+
mock_open().side_effect = FileNotFoundError(
396+
2, "No such file or directory", "path/to/non_existent_file.txt"
397+
)
398+
399+
with pytest.raises(SystemExit):
400+
main()
401+
386402

387403
class TestCLIMainQuiet:
388404
# main : quiet (directly checking stdout and stderr)

0 commit comments

Comments
 (0)