Is there any way to catch exceptions raised during rendering?

When an exception is raised during rendering, Solara displays its traceback as a plain text instead of a page layout. Is it possible to catch such exception and show its traceback in a component on a page? Something like React error boundary would be really helpful here.
5 Replies
MaartenBreddels
MaartenBreddels6mo ago
Good question, and there is an example at https://solara.dev/documentation/api/hooks/use_exception but that is broken (we'll need to look into that).
MaartenBreddels
MaartenBreddels6mo ago
I have a working example here, with a comment about a bug in reacton, I hope this helps you: https://app.py.cafe/snippet/solara/v1?projectId=htcps_fmjs
PyCafe - Solara - Exception Handler Using Solara
PyCafe: get your daily fix of Python!
Egor Makarenko
Egor MakarenkoOP6mo ago
Thank you! I experimented with that a bit and it seems that function components are working too: https://app.py.cafe/snippet/solara/v1?projectId=iqmfu9u0mom
PyCafe - Solara - Exception Handler Using Solara
PyCafe: get your daily fix of Python!
MaartenBreddels
MaartenBreddels6mo ago
Nice, did you find a pattern in it? When it works and when it does not?
Egor Makarenko
Egor MakarenkoOP6mo ago
It is strange, but replacing solara.VBox() with rv.Html(tag="div") fixes the use_exception example
Want results from more Discord servers?
Add your server