Skip to content

Commit e924c6e

Browse files
committed
Add error handling for non-existent or invalid tool folder in load_tools_from_folder
1 parent c5a3fa7 commit e924c6e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

toolit/auto_loader.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from toolit.create_apps_and_register import register_command
1616
from types import FunctionType, ModuleType
1717
from typing import Callable
18-
18+
import typer
1919

2020
def get_items_from_folder(
2121
folder_path: pathlib.Path,
@@ -56,6 +56,15 @@ def load_tools_from_folder(folder_path: pathlib.Path) -> list[FunctionType]:
5656
5757
Folder is relative to the project's working directory.
5858
"""
59+
if not folder_path.exists() or not folder_path.is_dir():
60+
msg = (
61+
"No tools loaded.\n"
62+
"The folder selected for devtools does not exist or is not a directory.\n"
63+
f"{folder_path.absolute().as_posix()}\n"
64+
"Please create it and add your tools there."
65+
)
66+
typer.secho(f"\n{'='*60}\nERROR: {msg}\n{'='*60}\n", fg=typer.colors.RED, bold=True)
67+
return []
5968
# If folder_path is relative, compute its absolute path using the current working directory.
6069
if not folder_path.is_absolute():
6170
folder_path = pathlib.Path.cwd() / folder_path

0 commit comments

Comments
 (0)