report the context, if possible, on python tracebacks

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?"
pull/9664/head
Eli Schwartz 3 years ago
parent bea735dd76
commit 3c039f42a0
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 10
      mesonbuild/mesonmain.py

@ -27,7 +27,7 @@ import shutil
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
@ -144,10 +144,16 @@ class CommandLineParser:
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()

Loading…
Cancel
Save