Skip to content

✨ Add pretty_exceptions_suppress option to extend suppressed frames in pretty exceptions - #770

Closed
tlambert03 wants to merge 3 commits into
fastapi:masterfrom
tlambert03:suppress
Closed

✨ Add pretty_exceptions_suppress option to extend suppressed frames in pretty exceptions#770
tlambert03 wants to merge 3 commits into
fastapi:masterfrom
tlambert03:suppress

Conversation

@tlambert03

@tlambert03 tlambert03 commented Mar 27, 2024

Copy link
Copy Markdown

This pull request extends the pretty_exceptions feature by adding pretty_exceptions_suppress, which lets the user pass an iterable of modules or string paths to suppress in addition to Typer and click

@github-actions

This comment was marked as outdated.

@svlandeg svlandeg added feature New feature, enhancement or request p3 labels Mar 28, 2024
@Mark90

Mark90 commented Aug 22, 2025

Copy link
Copy Markdown

I'm not a maintainer, but the change looks pretty straight-forward to me.
Would be great if this option could be added.
Maybe this can be rebased and reviewed, or does it need to be linked to a feature issue first?

@github-actions

Copy link
Copy Markdown
Contributor

@tlambert03

Copy link
Copy Markdown
Author

fixed conflicts. Would be great to get a review from any maintainer. @tiangolo, @svlandeg? This has sat here for quite a while now. Do you have any thoughts?

@svlandeg

Copy link
Copy Markdown
Member

I'll have a look! 🙏

@svlandeg svlandeg self-assigned this Aug 25, 2025
@svlandeg svlandeg changed the title feat: Add pretty_exceptions_suppress option to extend suppressed frames in pretty exceptions ✨ Add pretty_exceptions_suppress option to extend suppressed frames in pretty exceptions Aug 25, 2025

@svlandeg svlandeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution!

While I can see how it might occassionally be useful to set this explicitely, I'm not sure how frequent this type of use-case is. And we always have to balance new features vs. the maintenance cost. Either way - I'll let Tiangolo decide on whether or not he'll want to include the feature in the library.

I left some further comments to try and get this PR into a good state to merge it, if Tiangolo agrees.


</div>

## Suppress Frames from Pretty Exceptions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's a few things we need to do to improve the docs here:

  • Move this section up to BEFORE the section "Disable Short Output"
  • Anywhere on this page, whenever it talks about "Click and Typer" being excluded, it should instead reference the "suppressed libraries" (or such, depending on exact wording used in the new section)
  • The example given here should be a full example, as in all other sections on this page. That means it should be a fully runnable code example that has sqlmodel lines in its error stack trace, and the output should be displayed so the user can verify it
  • The example should be tested properly in the test suite at tests/test_tutorial/test_exceptions, at which point it should check e.g. that sqlalchemy is part of the output (or not) with the setting off (or on).

BTW - is "frames" the correct term here? I would have opted for "Libraries", but I'm not sure either way.


## Disable Pretty Exceptions

You can also entirely disable pretty exceptions with the parameter `pretty_exceptions_enable=False`:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Question: what should happen when both pretty_exceptions_short=False and pretty_exceptions_suppress=[sqlalchemy] are set?

## Suppress Frames from Pretty Exceptions

By default, typer will **omit** all the parts of the traceback that come from the internal parts in Typer and Click, but you can exclude frames from additional
frameworks using `pretty_exceptions_suppress`, which should be a list of modules or str paths.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How exactly would "str paths" be defined?

@svlandeg svlandeg removed their assignment Aug 25, 2025
@github-actions github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Sep 1, 2025
@github-actions

github-actions Bot commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

This pull request has a merge conflict that needs to be resolved.

@github-actions

Copy link
Copy Markdown
Contributor

As this PR has been waiting for the original user for a while but seems to be inactive, it's now going to be closed. But if there's anyone interested, feel free to create a new PR.

@github-actions github-actions Bot closed this Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts Automatically generated when a PR has a merge conflict feature New feature, enhancement or request p3 waiting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants