Skip to content

Commit

Permalink
handle OSError exception in run function
Browse files Browse the repository at this point in the history
  • Loading branch information
duckflyer authored and nirbheek committed Aug 8, 2022
1 parent c6d0cb6 commit 21796bd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion mesonbuild/mesonmain.py
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

# Work around some pathlib bugs...

from . import _pathlib
import sys
sys.modules['pathlib'] = _pathlib
Expand Down Expand Up @@ -158,6 +159,18 @@ def run(self, args):
if os.environ.get('MESON_FORCE_BACKTRACE'):
raise
return 1
except OSError as e:
if os.environ.get('MESON_FORCE_BACKTRACE'):
raise
traceback.print_exc()
error_msg = os.linesep.join([
"Unhandled python exception",
f"{e.strerror} - {e.args}",
"this is probably not a Meson bug."])

mlog.exception(error_msg)
return e.errno

except Exception as e:
if os.environ.get('MESON_FORCE_BACKTRACE'):
raise
Expand All @@ -168,7 +181,7 @@ def run(self, args):
# - 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' and not isinstance(e, PermissionError):
if command != 'runpython':
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
Expand Down

0 comments on commit 21796bd

Please sign in to comment.