Cleanup: Catch RuntimeError on upper level
MODIFY
plextraktsync/cli.py
plextraktsync/cli.py
@@ -23,7 +23,13 @@ def wrap(*args, **kwargs):
name = fn.__name__
module = importlib.import_module(f'.commands.{name}', package=__package__)
cmd = getattr(module, name)
+
+ try:
cmd(*args, **kwargs)
+ except RuntimeError as e:
+ from click import ClickException
+
+ raise ClickException(f"Error running {name} command: {str(e)}")
return wrap

MODIFY
plextraktsync/commands/sync.py
plextraktsync/commands/sync.py
from typing import List
import click
-from click import ClickException
from tqdm import tqdm
from plextraktsync.commands.login import ensure_login
@@ -49,17 +48,11 @@ def sync(
click.echo("Nothing to sync, this is likely due conflicting options given.")
return
- try:
w.print_plan(print=tqdm.write)
- except RuntimeError as e:
- raise ClickException(str(e))
if dry_run:
print("Enabled dry-run mode: not making actual changes")
with measure_time("Completed full sync"):
- try:
runner = factory.sync()
runner.sync(walker=w, dry_run=config.dry_run)
- except RuntimeError as e:
- raise ClickException(str(e))

Cleanup: Catch RuntimeError on upper level