Skip to content

fix(ctl): let typer.Exit propagate so CLI commands exit without a traceback#1048

Merged
ogenstad merged 2 commits into
stablefrom
pog-catch-typer-exit-IHS-237
Jun 3, 2026
Merged

fix(ctl): let typer.Exit propagate so CLI commands exit without a traceback#1048
ogenstad merged 2 commits into
stablefrom
pog-catch-typer-exit-IHS-237

Conversation

@ogenstad
Copy link
Copy Markdown
Contributor

@ogenstad ogenstad commented May 28, 2026

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

  • Catch error from typer early and avoid showing it to the end user
  • Tests

Summary by cubic

Fixes infrahubctl so commands that raise typer.Exit exit cleanly without the "Error: 1" line or a traceback. Addresses IHS-237 by ensuring infrahubctl schema load prints only the human-readable error and exits with code 1.

  • Bug Fixes
    • Let typer.Exit pass through in catch_exception (sync/async) and handle_exception, removing click.exceptions.Exit interception so Typer exits cleanly without a traceback.
    • Add tests for typer.Typer and AsyncTyper to verify clean output, correct exit code, and no "Error: 1" line.

Written for commit b394707. Summary will update on new commits.

Review in cubic

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

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              
Flag Coverage Δ
integration-tests 41.57% <100.00%> (-0.02%) ⬇️
python-3.10 55.08% <100.00%> (-0.01%) ⬇️
python-3.11 55.10% <100.00%> (+0.01%) ⬆️
python-3.12 55.08% <100.00%> (-0.03%) ⬇️
python-3.13 55.10% <100.00%> (-0.01%) ⬇️
python-3.14 55.08% <100.00%> (-0.03%) ⬇️
python-filler-3.12 22.38% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/ctl/utils.py 68.30% <100.00%> (-0.23%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ogenstad ogenstad force-pushed the pog-catch-typer-exit-IHS-237 branch from 712ffcf to 60fa53d Compare June 2, 2026 14:20
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Jun 2, 2026

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

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

View logs

@ogenstad ogenstad marked this pull request as ready for review June 2, 2026 14:53
@ogenstad ogenstad requested a review from a team as a code owner June 2, 2026 14:53
Comment thread infrahub_sdk/ctl/utils.py Outdated
try:
return await func(*args, **kwargs)
except typer.Exit:
raise
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little surprised this fixes the issue. it looks like it's just catching the exception and then raising it again

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajtmccarty, do you think it's cleaner with the changes in b394707?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I think this is easier to understand now

@ogenstad ogenstad merged commit 0f26031 into stable Jun 3, 2026
21 checks passed
@ogenstad ogenstad deleted the pog-catch-typer-exit-IHS-237 branch June 3, 2026 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

infrahubctl: typer.Exit leaks raw traceback on schema load failure

2 participants