ewels / rich-click

Format click help output nicely with rich.
https://ewels.github.io/rich-click/
MIT License
630 stars 36 forks source link

dbt's CLI errors don't play nicely with `rich-click dbt ...` #141

Closed dwreeves closed 1 year ago

dwreeves commented 1 year ago

Example when wrapping the dbt CLI.

I ran rich-click dbt compile and hit an error, which then raised a separate error that couldn't be parsed.

The issue appears to be that they are subclassing ClickException but they don't set the message attribute. I wonder if there is a way to resolve this more safely.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../python3.11/site-packages/rich_click/rich_command.py", line 126, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File ".../python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../python3.11/site-packages/dbt/cli/main.py", line 155, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File ".../python3.11/site-packages/dbt/cli/requires.py", line 93, in wrapper
    raise ExceptionExit(e)
dbt.cli.exceptions.ExceptionExit: <exception str() failed>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/dreeves/Projects/battery-data/venv_dbt/bin/rich-click", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File ".../python3.11/site-packages/rich_click/cli.py", line 141, in main
    return function()
           ^^^^^^^^^^
  File ".../python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../python3.11/site-packages/rich_click/rich_command.py", line 141, in main
    rich_format_error(e, self.formatter)
  File ".../python3.11/site-packages/rich_click/rich_click.py", line 782, in rich_format_error
    highlighter(self.format_message()),
                ^^^^^^^^^^^^^^^^^^^^^
  File ".../python3.11/site-packages/click/exceptions.py", line 35, in format_message
    return self.message
           ^^^^^^^^^^^^
AttributeError: 'ExceptionExit' object has no attribute 'message'