Skip to content

Commit f74bef7

Browse files
committed
precommit fix
1 parent 35e8897 commit f74bef7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

codeflash/code_utils/env_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import os
4+
import sys
45
import tempfile
56
from functools import lru_cache
67
from pathlib import Path
@@ -27,8 +28,13 @@ def check_formatter_installed(formatter_cmds: list[str]) -> bool:
2728
f.write(tmp_code)
2829
f.flush()
2930
tmp_file = Path(f.name)
30-
format_code(formatter_cmds, tmp_file)
31-
tmp_file.unlink(missing_ok=True)
31+
try:
32+
format_code(formatter_cmds, tmp_file)
33+
except Exception:
34+
print(
35+
"⚠️ Failed to format code since formatter was not found in the environment. Please install it and try again."
36+
)
37+
sys.exit(1)
3238
return return_code
3339

3440

codeflash/code_utils/formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def format_code(formatter_cmds: list[str], path: Path) -> str:
3131
console.rule(f"Formatted Successfully with: {formatter_name.replace('$file', path.name)}")
3232
else:
3333
logger.error(f"Failed to format code with {' '.join(formatter_cmd_list)}")
34-
except FileNotFoundError as e:
34+
except (FileNotFoundError, NotADirectoryError) as e:
3535
from rich.panel import Panel
3636
from rich.text import Text
3737

0 commit comments

Comments
 (0)