Skip to content

Commit bfb9823

Browse files
Improve exception handling for parsing arguments.
1 parent d883a6d commit bfb9823

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,19 @@ def main() -> None: # noqa: D103
122122
# Parse arguments
123123
try:
124124
args = parser.parse_args()
125+
except ExpectedException as e:
126+
print(e.message, file=sys.stderr)
127+
sys.exit(e.error_code)
125128
except SystemExit as e:
126129
if e.code != 0:
127130
print(MESSAGE_ARG_GENERAL, file=sys.stderr)
128131
sys.exit(EC_ARG_GENERAL)
129132
# This happens when --help is used, exit gracefully
130133
sys.exit(0)
134+
except Exception as e:
135+
print(traceback.format_exc(), file=sys.stderr)
136+
print(f"Failed to run the program: {e}", file=sys.stderr)
137+
sys.exit(1)
131138

132139
if hasattr(args, "func"):
133140
# Check for updates only when help is not checked

0 commit comments

Comments
 (0)