Skip to content

Commit

Permalink
observer.py: Update error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Bernhard Kaindl <[email protected]>
  • Loading branch information
bernhardkaindl authored and psafont committed Apr 22, 2024
1 parent b0f6011 commit 67ae85f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions python3/packages/observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,18 +401,25 @@ def run(file):
return 0
except FileNotFoundError as e:
print(
f"{__file__}: {' '.join(sys.argv)}\n{e.filename}: No such file",
f"{__file__} {' '.join(sys.argv)}:\nScript not found: {e.filename}",
file=sys.stderr,
)
return 2
except Exception:
print(
f"{__file__}: {' '.join(sys.argv)}\n{traceback.format_exc()}",
file=sys.stderr)
except Exception as e:
print(f"{__file__} {' '.join(sys.argv)}:", file=sys.stderr) # the command
print("Exception in the traced script:", file=sys.stderr)
print(e, file=sys.stderr) # Print the exception message
print(traceback.format_exc(), file=sys.stderr) # Print the traceback
return 139 # This is what the default SIGSEGV handler on Linux returns

return run(argv0)


if __name__ == "__main__":
sys.exit(main())
# Only use sys.exit(ret) raising SystemExit() if the return code is not 0
# to allow test_observer_as_script() to get the globals of observer.py:

exit_code = main() # pylint: disable=invalid-name
logging.shutdown() # Reduces the unclosed socket warnings by PYTHONDEVMODE=yes
if exit_code:
sys.exit(exit_code)

0 comments on commit 67ae85f

Please sign in to comment.