Open pradyunsg opened 2 months ago
This is currently a draft since I'm not sure how exactly exceptions within the rich object rendering should be handled -- I'm leaning toward trying to catch them and presenting a fallback like "render failed" or similar. Not quite sure how to do that, so figured I'd open this as a draft PR in case y'all have any opinions/suggestions on how to achieve that.
OK, I think I figured out something that works! 🎉
Using the Console
object to eagerly render the exception and iterating through to collect all the segments, before yielding those segments forward. This enables this logic to catch any rendering-related issues inline, rather than needing to handle them at some other level (eg: console.render
).
Marking this as ready for review, since I think everything that is necessary to land this is in place now[^1] -- code, tests, documentation, changelog, contributing.md. :)
[^1]: Assuming of course that there are no concerns with the implementation/approach. 😉
Oh, and here's an SVG showing that this works!
Type of changes
Checklist
Description
See https://github.com/Textualize/rich/discussions/2717 for discussion. This enables exceptions to be rich objects and be rendered via the rich rendering pipeline, in tracebacks. This can be tested manually by running
python -m rich.traceback
whose example now uses a rich object instead of theNameError
.