Skip to content

Commit

Permalink
report the context, if possible, on python tracebacks
Browse files Browse the repository at this point in the history
The interpreter tries to catch any exception and add the latest node
information to it, but currently we only used that to print better
formatted error messages on MesonException.

Since we should theoretically have that property for most/all
exceptions, let's percolate that upward, and message the user that an
unexpected traceback was encountered, that it should be reported as a
bug, and the helpful information of "how far into parsing this
meson.build did we get before erroring out, anyway?"
  • Loading branch information
eli-schwartz committed Nov 29, 2021
1 parent bea735d commit 3c039f4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mesonbuild/mesonmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from . import mesonlib
from . import mlog
from . import mconf, mdist, minit, minstall, mintro, msetup, mtest, rewriter, msubprojects, munstable_coredata, mcompile, mdevenv
from .mesonlib import MesonException
from .mesonlib import MesonException, MesonBugException
from .environment import detect_msys2_arch
from .wrap import wraptool

Expand Down Expand Up @@ -144,10 +144,16 @@ def run(self, args):
if os.environ.get('MESON_FORCE_BACKTRACE'):
raise
return 1
except Exception:
except Exception as e:
if os.environ.get('MESON_FORCE_BACKTRACE'):
raise
traceback.print_exc()
msg = 'Unhandled python exception'
if all(getattr(e, a, None) is not None for a in ['file', 'lineno', 'colno']):
e = MesonBugException(msg, e.file, e.lineno, e.colno) # type: ignore
else:
e = MesonBugException(msg)
mlog.exception(e)
return 2
finally:
mlog.shutdown()
Expand Down

0 comments on commit 3c039f4

Please sign in to comment.