Skip to content

Commit 23454d2

Browse files
committed
Fix error message in case of missing module
1 parent 2410268 commit 23454d2

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/aoc/main.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,31 @@
99
app = typer.Typer(no_args_is_help=True)
1010

1111

12+
def echo(text, fg=typer.colors.GREEN):
13+
typer.echo(
14+
typer.style(
15+
text,
16+
fg=fg,
17+
)
18+
)
19+
20+
1221
def import_challenge_module(day: int):
22+
module_name = f"aoc.day_{day:02}"
1323
try:
14-
module = importlib.import_module(f"aoc.day_{day:02}")
24+
module = importlib.import_module(module_name)
1525
except ModuleNotFoundError as e:
16-
typer.echo(
17-
typer.style(
18-
f'You have not solved day {day} yet. Start it using "new-day" command',
26+
echo(
27+
f'Could not import "{e.name}"',
28+
fg=typer.colors.RED,
29+
)
30+
if e.name == module_name:
31+
echo(
32+
f"You have not solved day {day} yet. Start it using 'new-day' command",
1933
fg=typer.colors.RED,
2034
)
21-
)
35+
else:
36+
raise e
2237
raise typer.Exit(1) from e
2338
return module
2439

0 commit comments

Comments
 (0)