diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b528b2..676ba22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add `--debug` flag to see stack of exceptions, [PR-7](https://github.com/panda-official/DriftCLI/pull/7) + ## [0.4.0] - 2023-03-15 ### Added diff --git a/drift_cli/alias.py b/drift_cli/alias.py index 60f64d4..5ebae33 100644 --- a/drift_cli/alias.py +++ b/drift_cli/alias.py @@ -63,7 +63,7 @@ def add( if bucket is None: bucket = click.prompt("Bucket", type=str, default="data") - with error_handle(): + with error_handle(ctx.obj["debug"]): entry = Alias(address=address, password=password, bucket=bucket) conf.aliases[name] = entry diff --git a/drift_cli/cli.py b/drift_cli/cli.py index 5d620cd..c8b1fff 100644 --- a/drift_cli/cli.py +++ b/drift_cli/cli.py @@ -25,11 +25,18 @@ type=int, help="Number of parallel tasks to use, defaults to 10", ) +@click.option( + "--debug", + "-d", + is_flag=True, + help="Enable debug logging", +) @click.pass_context def cli( ctx, config: Optional[Path] = None, parallel: Optional[int] = None, + debug: bool = False, ): """CLI client for PANDA | Drift Platform""" if config is None: @@ -43,6 +50,7 @@ def cli( ctx.obj["config_path"] = config ctx.obj["parallel"] = parallel + ctx.obj["debug"] = debug cli.add_command(alias, "alias") diff --git a/drift_cli/export.py b/drift_cli/export.py index 3b07c56..fd9ddbc 100644 --- a/drift_cli/export.py +++ b/drift_cli/export.py @@ -91,7 +91,7 @@ def raw( run = loop.run_until_complete client = DriftClient(alias.address, alias.password, loop=loop) - with error_handle(): + with error_handle(ctx.obj["debug"]): run( export_raw( client, diff --git a/drift_cli/utils/error.py b/drift_cli/utils/error.py index 1c9dfe9..38f0baa 100644 --- a/drift_cli/utils/error.py +++ b/drift_cli/utils/error.py @@ -7,10 +7,14 @@ @contextmanager -def error_handle(): - """Wrap try-catch block and print errorr""" - try: +def error_handle(debug: bool): + """Wrap try-catch block and print error""" + if debug: + # If debug is enabled, we don't want to catch any errors and wrap them yield - except Exception as err: - error_console.print(f"[{type(err).__name__}] {err}") - raise Abort() from err + else: + try: + yield + except Exception as err: + error_console.print(f"[{type(err).__name__}] {err}") + raise Abort() from err diff --git a/drift_cli/utils/helpers.py b/drift_cli/utils/helpers.py index 8fcef33..60d07a7 100644 --- a/drift_cli/utils/helpers.py +++ b/drift_cli/utils/helpers.py @@ -88,8 +88,13 @@ def _to_timestamp(date: str) -> float: def stop_signal(): signal_queue.put_nowait("stop") - loop.add_signal_handler(signal.SIGINT, stop_signal) - loop.add_signal_handler(signal.SIGTERM, stop_signal) + try: + loop.add_signal_handler(signal.SIGINT, stop_signal) + loop.add_signal_handler(signal.SIGTERM, stop_signal) + except NotImplementedError: + error_console.print( + "Signals are not supported on this platform. No graceful shutdown possible." + ) packages = await loop.run_in_executor( pool, client.get_package_names, topic, start, stop diff --git a/pyproject.toml b/pyproject.toml index 9976e08..b0d58ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = ["setuptools>=40.8.0", "wheel"] [project] name = "drift-cli" -version = "0.4.0" +version = "0.5.0" description = "CLI client for PANDA | Drift Platform" requires-python = ">=3.8" readme = "README.md"