Use predefined exception instead of arbitrary exit code in command modules#995
Open
zhenchaoni wants to merge 3 commits into
Open
Use predefined exception instead of arbitrary exit code in command modules#995zhenchaoni wants to merge 3 commits into
zhenchaoni wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #509. Replaces bare
sys.exit(N)/ctx.exit(N)/raise SystemExit(N)calls in command modules with predefined, typed exceptions so exit codes are managed consistently instead of scattered as magic numbers. No exit-code definitions change — codes 1/2/3/4 are preserved exactly.Changes
utils/cli.py:ModelLoadError→ exit 3 (model fails to load on device/EP)InferenceError→ exit 4 (prediction fails at runtime)PartialSupportError→ exit 1 (valid negative result; raised silently, noError:prefix)ModelLoadError/InferenceErroroverrideshow()to print the message verbatim, preserving existing stderr output.analyze.py: removedsysimport; all exits now raiseUsageError(2) orPartialSupportError(1); added a re-raise guard so intentional exits aren't relabeled "Analysis failed".run.py: parse/format/file errors →UsageError(2); load →ModelLoadError(3); inference →InferenceError(4); success no-input path keepsctx.exit(0).perf.py/serve.py: install/load failures →ClickException(1), with a re-raise guard inperf.Exit code contract (unchanged)
Testing
runtests asserting exit 3/4 are unchanged and still pass — behavior is fully guarded.run,run_spec,perf_cli,optracing,serve); no type/lint errors.