Skip to content

Commit

Permalink
Ensure main() catches all exceptions
Browse files Browse the repository at this point in the history
Previously the exception handling was outside of main(), which meant
that exceptions were only caught when codebasin was launched as a module
(i.e., with python3 -m codebasin); the codebasin script generated by
pyproject.toml did not catch exceptions.

Signed-off-by: John Pennycook <[email protected]>
  • Loading branch information
Pennycook committed Oct 11, 2024
1 parent 20d11b4 commit 50a202a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions codebasin/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def warn(self):
meta_warning.warn()


def main():
def _main():
# Read command-line arguments
parser = argparse.ArgumentParser(
description="Code Base Investigator " + str(version),
Expand Down Expand Up @@ -359,10 +359,14 @@ def report_enabled(name):
sys.exit(0)


if __name__ == "__main__":
def main():
try:
sys.argv[0] = "codebasin"
main()
_main()
except Exception as e:
log.error(str(e))
sys.exit(1)


if __name__ == "__main__":
sys.argv[0] = "codebasin"
main()

0 comments on commit 50a202a

Please sign in to comment.