Skip to content

Commit

Permalink
Print the traceback when reporting an error
Browse files Browse the repository at this point in the history
  • Loading branch information
jasujm committed May 12, 2020
1 parent a026aec commit 830f0d6
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions python/enumecg/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
:func:`cli()`.
"""

import sys
import traceback

import click
import yaml

Expand All @@ -19,13 +22,13 @@ def _get_enum_values(Enum):
return [e.value for e in Enum.__members__.values()]


def _report_error_and_fail(message, abort):
def _report_error_and_fail(message):
click.secho(message, err=True, fg="red")
abort()
traceback.print_exc()
raise click.Abort()


@click.command()
@click.pass_context
@click.option(
"--documentation",
type=click.Choice(_get_enum_values(DocumentationStyle)),
Expand All @@ -38,7 +41,7 @@ def _report_error_and_fail(message, abort):
)
@click.option("--value-type", help="Enumerator value type")
@click.argument("file", type=click.File(), default="-")
def cli(ctx, file, documentation, primary_type, value_type):
def cli(file, documentation, primary_type, value_type):
"""Generate C++ boilerplate for an Enhanced Enum definition
This executable is a part of the Enhanced Enum library. It is used
Expand All @@ -57,8 +60,8 @@ def cli(ctx, file, documentation, primary_type, value_type):
"""
try:
enum = yaml.safe_load(file)
except yaml.YAMLError as e:
_report_error_and_fail(f"Failed to load {file.name}: {e}", ctx.abort)
except:
_report_error_and_fail(f"Failed to load {file.name}")

try:
output = generate(
Expand All @@ -67,7 +70,7 @@ def cli(ctx, file, documentation, primary_type, value_type):
primary_type=primary_type,
value_type=value_type,
)
except Error as e:
_report_error_and_fail(f"Failed to generate code from {enum!r}: {e}", ctx.abort)
except:
_report_error_and_fail(f"Failed to generate code from {file.name}")

click.echo(output)

0 comments on commit 830f0d6

Please sign in to comment.