Skip to content

Commit 4743d6d

Browse files
committed
feat: add error handling and show local repo path if provided
Signed-off-by: Demolus13 <[email protected]>
1 parent 96798cf commit 4743d6d

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/macaron/__main__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
)
2121
from macaron.config.defaults import create_defaults, load_defaults
2222
from macaron.config.global_config import global_config
23-
from macaron.console import access_handler
23+
from macaron.console import RichConsoleHandler, access_handler
2424
from macaron.errors import ConfigurationError
2525
from macaron.output_reporter.reporter import HTMLReporter, JSONReporter, PolicyReporter
2626
from macaron.policy_engine.policy_engine import run_policy_engine, show_prelude
@@ -630,7 +630,7 @@ def main(argv: list[str] | None = None) -> None:
630630
# Set global logging config. We need the stream handler for the initial
631631
# output directory checking log messages.
632632
st_handler: logging.StreamHandler = logging.StreamHandler(sys.stdout)
633-
rich_handler: logging.Handler = logging.Handler()
633+
rich_handler: RichConsoleHandler = access_handler.set_handler(args.verbose)
634634
if args.disable_rich_output:
635635
if args.verbose:
636636
log_level = logging.DEBUG
@@ -710,6 +710,10 @@ def main(argv: list[str] | None = None) -> None:
710710
sys.exit(os.EX_NOINPUT)
711711

712712
perform_action(args)
713+
except KeyboardInterrupt:
714+
if not args.disable_rich_output:
715+
rich_handler.error("Macaron failed: Interrupted by user")
716+
sys.exit(os.EX_SOFTWARE)
713717
finally:
714718
if args.disable_rich_output:
715719
st_handler.close()

src/macaron/console.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __init__(self, *args: Any, verbose: bool = False, **kwargs: Any) -> None:
105105
title_align="left",
106106
border_style="blue",
107107
)
108+
self.error_message: str = ""
108109
self.live = Live(get_renderable=self.make_layout, refresh_per_second=10)
109110

110111
def emit(self, record: logging.LogRecord) -> None:
@@ -521,8 +522,31 @@ def make_layout(self) -> Group:
521522
layout = layout + [self.gen_build_spec_table]
522523
if self.verbose:
523524
layout = layout + ["", self.verbose_panel]
525+
if self.error_message:
526+
error_panel = Panel(
527+
self.error_message,
528+
title="Error",
529+
title_align="left",
530+
border_style="red",
531+
)
532+
layout = layout + ["", error_panel]
524533
return Group(*layout)
525534

535+
def error(self, message: str) -> None:
536+
"""
537+
Handle error logging.
538+
539+
Parameters
540+
----------
541+
message : str
542+
The error message to be logged.
543+
544+
Returns
545+
-------
546+
None
547+
"""
548+
self.error_message = message
549+
526550
def start(self, command: str) -> None:
527551
"""
528552
Start the live console display.

src/macaron/repo_finder/repo_finder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ def prepare_repo(
480480
else:
481481
logger.info("Checking if the path to repo %s is a local path.", repo_path)
482482
resolved_local_path = resolve_local_path(get_local_repos_path(), repo_path)
483+
rich_handler.add_description_table_content("Local Cloned Path:", resolved_local_path)
483484

484485
if resolved_local_path:
485486
try:

0 commit comments

Comments
 (0)