Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 8932d87

Browse files
committed
validate.py distinguish internal errors from invalid files
1 parent 130afac commit 8932d87

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/ifcopenshell-python/ifcopenshell/validate.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,17 @@ def emit(self, record):
598598
import sys
599599
import logging
600600

601+
def handle_exception(exc_type, exc_value, exc_traceback):
602+
import traceback
603+
604+
print(f"Unhandled exception: {exc_value}", file=sys.stderr)
605+
traceback.print_tb(exc_traceback, file=sys.stderr)
606+
# Exit with a negative code so that it's possible to distinguish
607+
# internal errors from invalid files.
608+
sys.exit(-1)
609+
610+
sys.excepthook = handle_exception
611+
601612
filenames = [x for x in sys.argv[1:] if not x.startswith("--")]
602613
flags = set(x for x in sys.argv[1:] if x.startswith("--"))
603614
some_file_is_invalid = False

0 commit comments

Comments
 (0)