Skip to content

Commit dfaa1cb

Browse files
committed
raise proper exception
1 parent bc31a61 commit dfaa1cb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

codeflash/cli_cmds/cmd_init.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,14 @@ def test_sort():
916916

917917

918918
def run_end_to_end_test(args: Namespace, bubble_sort_path: str, bubble_sort_test_path: str) -> None:
919+
try:
920+
check_formatter_installed(args.formatter_cmds)
921+
except Exception: # noqa: BLE001
922+
logger.error(
923+
"Formatter not found. Review the formatter_cmds in your pyproject.toml file and make sure the formatter is installed."
924+
)
925+
return
926+
919927
command = ["codeflash", "--file", "bubble_sort.py", "--function", "sorter"]
920928
if args.no_pr:
921929
command.append("--no-pr")

codeflash/code_utils/env_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
from codeflash.code_utils.shell_utils import read_api_key_from_shell_config
1111

1212

13+
class FormatterNotFoundError(Exception):
14+
"""Exception raised when a formatter is not found."""
15+
16+
def __init__(self, formatter_cmd: str) -> None:
17+
super().__init__(f"Formatter command not found: {formatter_cmd}")
18+
1319
def check_formatter_installed(formatter_cmds: list[str]) -> bool:
1420
return_code = True
1521
if formatter_cmds[0] == "disabled":
@@ -34,7 +40,7 @@ def check_formatter_installed(formatter_cmds: list[str]) -> bool:
3440
tmp_file.unlink(missing_ok=True)
3541
if not return_code:
3642
msg = f"Error running formatter command: {command}"
37-
raise logger.error(msg) # type: ignore
43+
raise FormatterNotFoundError(msg)
3844
return return_code
3945

4046

0 commit comments

Comments
 (0)