Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --debug flag to see stack of exceptions #7

Merged
merged 3 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion drift_cli/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions drift_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -43,6 +50,7 @@ def cli(

ctx.obj["config_path"] = config
ctx.obj["parallel"] = parallel
ctx.obj["debug"] = debug


cli.add_command(alias, "alias")
Expand Down
2 changes: 1 addition & 1 deletion drift_cli/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 10 additions & 6 deletions drift_cli/utils/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 7 additions & 2 deletions drift_cli/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down