Qix- / better-exceptions

Pretty and useful exceptions in Python, automatically.
MIT License
4.59k stars 203 forks source link

FileNotFoundError on PyPy #102

Open ram-bv opened 4 years ago

ram-bv commented 4 years ago

I got this error running on pypy3.6-v7.3.0-linux64:

Error calling sys.excepthook:
Traceback (most recent call last):
  File "<builtin>/app_main.py", line 146, in display_exception
  File "/floof/pypy3.6-v7.3.0-linux64/site-packages/better_exceptions/__init__.py", line 53, in excepthook
    formatted = format_exception(exc, value, tb)
  File "/floof/pypy3.6-v7.3.0-linux64/site-packages/better_exceptions/__init__.py", line 49, in format_exception
    return formatter.format_exception(exc, value, tb)
  File "/floof/pypy3.6-v7.3.0-linux64/site-packages/better_exceptions/formatter.py", line 314, in format_exception
    return u''.join(formatted for formatted in self._format_exception(value, tb))
  File "/floof/pypy3.6-v7.3.0-linux64/site-packages/better_exceptions/formatter.py", line 314, in <genexpr>
    return u''.join(formatted for formatted in self._format_exception(value, tb))
  File "/floof/pypy3.6-v7.3.0-linux64/site-packages/better_exceptions/formatter.py", line 303, in _format_exception
    formatted, colored_source = self.format_traceback(exc_traceback)
  File "/floof/pypy3.6-v7.3.0-linux64/site-packages/better_exceptions/formatter.py", line 266, in format_traceback
    formatted, colored = self.format_traceback_frame(tb)
  File "/floof/pypy3.6-v7.3.0-linux64/site-packages/better_exceptions/formatter.py", line 226, in format_traceback_frame
    filename, lineno, function, source, color_source, relevant_values = self.get_traceback_information(tb)
  File "/floof/pypy3.6-v7.3.0-linux64/site-packages/better_exceptions/formatter.py", line 198, in get_traceback_information
    frame_info = inspect.getframeinfo(tb)
  File "/floof/pypy3.6-v7.3.0-linux64/lib-python/3/inspect.py", line 1458, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
  File "/floof/pypy3.6-v7.3.0-linux64/lib-python/3/inspect.py", line 700, in getsourcefile
    if getattr(getmodule(object, filename), '__loader__', None) is not None:
  File "/floof/pypy3.6-v7.3.0-linux64/lib-python/3/inspect.py", line 729, in getmodule
    file = getabsfile(object, _filename)
  File "/floof/pypy3.6-v7.3.0-linux64/lib-python/3/inspect.py", line 713, in getabsfile
    return os.path.normcase(os.path.abspath(_filename))
  File "/floof/pypy3.6-v7.3.0-linux64/lib-python/3/posixpath.py", line 383, in abspath
    cwd = os.getcwd()
FileNotFoundError: [Errno 2] No such file or directory

This is frustrating because I can't know what's the directory it's not finding. Can better-exceptions deal with such problems with graceful degradation? If a certain frame has a missing task, it's better to mark it as missing than crash.

alexmojaki commented 4 years ago

I know it looks weird but I ran into this too recently, os.getcwd() itself needs to open some file under the hood, I don't know why. Check if it works on its own?

ram-bv commented 4 years ago

Damn Alex, are you stalking me? ;)

This is my work account, by the way.

I confirmed os.getcwd() works on its own. It's curious that it would fail when called inside abspath. In any case I'd recommend that even if PyPy or the standard library have bugs in that code, that better-exception should degrade gracefully when they happen.

Qix- commented 4 years ago

We can wrap it, though it's a matter of what to do in lieu of the existing logic if an exception is raised.

ram-bv commented 4 years ago

I'd show something like SOURCE UNAVAILABLE for those frames, anything besides failing.