sdispater / clikit

CliKit is a group of utilities to build beautiful and testable command line interfaces.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle crashes from missing `cwd` better

dimaqq opened this issue · comments

From python-poetry/poetry#3455

[snipped]

uring handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/ikkamens/.poetry/bin/poetry", line 19, in <module>
    main()
  File "/Users/ikkamens/.poetry/lib/poetry/console/__init__.py", line 5, in main
    return Application().run()
  File "/Users/ikkamens/.poetry/lib/poetry/_vendor/py3.9/clikit/console_application.py", line 142, in run
    trace.render(io, simple=isinstance(e, CliKitException))
  File "/Users/ikkamens/.poetry/lib/poetry/_vendor/py3.9/clikit/ui/components/exception_trace.py", line 232, in render
    return self._render_exception(io, self._exception)
  File "/Users/ikkamens/.poetry/lib/poetry/_vendor/py3.9/clikit/ui/components/exception_trace.py", line 269, in _render_exception
    self._render_snippet(io, current_frame)
  File "/Users/ikkamens/.poetry/lib/poetry/_vendor/py3.9/clikit/ui/components/exception_trace.py", line 277, in _render_snippet
    self._get_relative_file_path(frame.filename),
  File "/Users/ikkamens/.poetry/lib/poetry/_vendor/py3.9/clikit/ui/components/exception_trace.py", line 405, in _get_relative_file_path
    cwd = os.getcwd()
FileNotFoundError: [Errno 2] No such file or directory

I guess trace.render(...) should fail gracefully when corrent cwd is missing and thus "relative file path" cannot be got, or even the source code at the exception call site cannot be found.