justpy
justpy copied to clipboard
please catch exceptions in callbacks automatically
It sometimes happen that a callback raises an exception — which is not reported anywhere. I am often writing callbacks like this:
@def callback(*args):
try:
do(something)
except BaseException as e:
traceback.print_exc()
Perhaps each callback could be automatically wrapped by JustPy so that the exception shows up in the log — I use the following so that it is formatted nicely:
log.error('Exception in '+__name__)
for l in traceback.format_exception(*sys.exc_info()):
for l2 in l[:-1].split('\n'): log.warning(l2)
Is this the relevant code in JustPy which would have to be wrapped?
https://github.com/elimintz/justpy/blob/f878a28babfa67d5ceccc13afa03e21f97a63708/justpy/htmlcomponents.py#L227-L237
I usually set CRASH to True in the justpy.env file:
# If set to True, the program terminates if there is an error in an event handler
CRASH = config('CRASH', cast=bool, default=False)
Your suggestion is much better for a production environment. It seems to me that a decorator for request handlers that adds the functionality you need is the best option. Alternatively, a configuration variable could be added and then the place to make the change would be the code you posted.
https://github.com/WolfgangFahl/pyJustpyWidgets/blob/da61fd153c7854b6bbee6a0d12841a87e01da013/jpwidgets/bt5widgets.py#L131 has a handleException function in the App base class.
Hi Wolfgang, I see you assigned a number of issues to me. I won't be available for justpy in foreseeable future unfortunately. Stay well.
On August 20, 2022 2:13:04 PM GMT+02:00, Wolfgang Fahl @.***> wrote:
https://github.com/WolfgangFahl/pyJustpyWidgets/blob/da61fd153c7854b6bbee6a0d12841a87e01da013/jpwidgets/bt5widgets.py#L131 has a handleException function in the App base class.
-- Reply to this email directly or view it on GitHub: https://github.com/elimintz/justpy/issues/196#issuecomment-1221303825 You are receiving this because you were assigned.
Message ID: @.***> -- Sent from my Android device with K-9 Mail. Please excuse my brevity.
@eudoxos thx for getting in touch. Could you please supply a single line pull request (e.g. with a comment line) which i can except so that you show up in the list of collaborators. I simply want to honor your contribution to justpy.
That is kind, thank you; see #465
see #685