refactor errorhandler for deduplication of logic
Mostly just move a comment around back to where it's more relevant, and
handle MESON_FORCE_TRACEBACK once instead of twice.
@@ -38,10 +38,18 @@ def errorhandler(e, command):
if os.environ.get('MESON_FORCE_BACKTRACE'):
raise e
return 1
- elif isinstance(e, OSError):
+ else:
+ # We assume many types of traceback are Meson logic bugs, but most
+ # particularly anything coming from the interpreter during `setup`.
+ # Some things definitely aren't:
+ # - PermissionError is always a problem in the user environment
+ # - runpython doesn't run Meson's own code, even though it is
+ # dispatched by our run()
if os.environ.get('MESON_FORCE_BACKTRACE'):
raise e
traceback.print_exc()
+
+ if isinstance(e, OSError):
error_msg = os.linesep.join([
"Unhandled python exception",
f"{e.strerror} - {e.args}",
@@ -49,17 +57,7 @@ def errorhandler(e, command):
mlog.exception(error_msg)
return e.errno
-
else: # Exception
- if os.environ.get('MESON_FORCE_BACKTRACE'):
- raise e
- traceback.print_exc()
- # We assume many types of traceback are Meson logic bugs, but most
- # particularly anything coming from the interpreter during `setup`.
- # Some things definitely aren't:
- # - PermissionError is always a problem in the user environment
- # - runpython doesn't run Meson's own code, even though it is
- # dispatched by our run()
if command != 'runpython':
msg = 'Unhandled python exception'
if all(getattr(e, a, None) is not None for a in ['file', 'lineno', 'colno']):
