10000 Unable to see EOFError exception in the traceback with disabled standalone mode · Issue #2379 · pallets/click · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Unable to see EOFError exception in the traceback with disabled standalone mode #2379
Closed
@atugushev

Description

@atugushev

According to the docs disabled standalone mode disables exception handling. However, click still suppresses EOFError (as well as KeyboardInterrupt) exceptions from the stack trace due to the raise ... from None construction, see:

click/src/click/core.py

Lines 1066 to 1068 in 0aec116

except (EOFError, KeyboardInterrupt):
echo(file=sys.stderr)
raise Abort() from None

I'd suggest changing the line to raise Abort() from e, so that users can see the original exception in the stack trace.

Real world example. I use asyncio streams that can raise IncompleteReadError which inherited from EOFError, but I can't see the exception in the stack trace even with disabled standalone mode which looks like a bug to me.

How to replicate the bug:

  1. Create the following script:
# t.py
import click


@click.command()
def cli():
    raise EOFError('I want to see this exception')


if __name__ == '__main__':
    cli.main(standalone_mode=False)
  1. Run module python -m t

Actual behavior:

Traceback (most recent call last):
  File "/Users/albert/.pyenv/versions/3.10.4/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/albert/.pyenv/versions/3.10.4/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/private/var/folders/l0/lnq1ghps5yqc4vkgszlcz92m0000gp/T/tmp.X1tRYLrm/t.py", line 10, in <module>
    cli.main(standalone_mode=False)
  File "/private/var/folders/l0/lnq1ghps5yqc4vkgszlcz92m0000gp/T/tmp.X1tRYLrm/.venv/lib/python3.10/site-packages/click/core.py", line 1068, in main
    raise Abort() from None
click.exceptions.Abort

Expected behavior:

Traceback (most recent call last):
  File "/private/var/folders/l0/lnq1ghps5yqc4vkgszlcz92m0000gp/T/tmp.X1tRYLrm/.venv/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/private/var/folders/l0/lnq1ghps5yqc4vkgszlcz92m0000gp/T/tmp.X1tRYLrm/.venv/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/private/var/folders/l0/lnq1ghps5yqc4vkgszlcz92m0000gp/T/tmp.X1tRYLrm/.venv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/private/var/folders/l0/lnq1ghps5yqc4vkgszlcz92m0000gp/T/tmp.X1tRYLrm/t.py", line 6, in cli
    raise EOFError('I want to see this exception')
EOFError: I want to see this exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/albert/.pyenv/versions/3.10.4/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/albert/.pyenv/versions/3.10.4/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/private/var/folders/l0/lnq1ghps5yqc4vkgszlcz92m0000gp/T/tmp.X1tRYLrm/t.py", line 10, in <module>
    cli.main(standalone_mode=False)
  File "/private/var/folders/l0/lnq1ghps5yqc4vkgszlcz92m0000gp/T/tmp.X1tRYLrm/.venv/lib/python3.10/site-packages/click/core.py", line 1068, in main
    raise Abort() from e
click.exceptions.Abort

Environment:

  • Python version: 3.10.4
  • Click version: 8.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0