fix(ctl): let typer.Exit propagate so CLI commands exit without a traceback#1048
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## stable #1048 +/- ##
==========================================
- Coverage 81.71% 81.71% -0.01%
==========================================
Files 135 135
Lines 11626 11625 -1
Branches 1759 1759
==========================================
- Hits 9500 9499 -1
Misses 1575 1575
Partials 551 551
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
712ffcf to
60fa53d
Compare
Deploying infrahub-sdk-python with
|
| Latest commit: |
b394707
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://657ba35c.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://pog-catch-typer-exit-ihs-237.infrahub-sdk-python.pages.dev |
| try: | ||
| return await func(*args, **kwargs) | ||
| except typer.Exit: | ||
| raise |
There was a problem hiding this comment.
I am a little surprised this fixes the issue. it looks like it's just catching the exception and then raising it again
There was a problem hiding this comment.
I can agree that it looks a bit confusing. What happens is that it's interrupting the catch just below where we send this into handle_exception. But I'll look at moving this instead into handle_exception which is a bit cleaner anyway.
There was a problem hiding this comment.
@ajtmccarty, do you think it's cleaner with the changes in b394707?
There was a problem hiding this comment.
yes I think this is easier to understand now
Why
Newer versions of typer behave differently and produce an error that's not as friendly as we'd want and we don't want to show that error.
Closes #1047
What changed
Summary by cubic
Fixes
infrahubctlso commands that raisetyper.Exitexit cleanly without the "Error: 1" line or a traceback. Addresses IHS-237 by ensuringinfrahubctl schema loadprints only the human-readable error and exits with code 1.typer.Exitpass through incatch_exception(sync/async) andhandle_exception, removingclick.exceptions.Exitinterception so Typer exits cleanly without a traceback.typer.TyperandAsyncTyperto verify clean output, correct exit code, and no "Error: 1" line.Written for commit b394707. Summary will update on new commits.