Replies: 1 comment
-
| I know this is old but in case someone else comes across this, here is a work around:  | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Duplicate Check
Describe the bug
I need to register a "catch-all" exception handler, to help identify bugs in development. Some errors may possibly arise from Flet controls but more often they will be result of backend API calls failing etc.
I previously did this via
sys.excepthookand it did the trick fine, but this was under Flet 0.19.0 and it appears this approach no longer works with Flet 0.21.2+I then turned to setting
Page.on_errorbut this either does not work, or at least does not do what I was hoping.I of course prefer to use latest Flet but currently this feels less "safe" given I have no insight to new errors.
Code sample
Logs
To reproduce
Running the code above with Flet 0.19.0 does print "GOT UNHANDLED ERROR" when clicking the button. But running it with newer Flet, the button click error still raises and a traceback is printed to console, but no "GOT UNHANDLED ERROR" message and so my custom hook is being ignored somehow.
I did try registering just the sys hook and then just the threading hook, to see which was actually getting called under Flet 0.19.0 and it seems the threading hook was being called, not the sys hook. But again neither gets called with newer Flet.
I then added the
Page.on_errorsnippet in the hopes it would get called, but it also is not getting called - this is true with both the older and newer Flet.Expected behavior
I need a reliable way to detect unhandled errors, so I can "handle" them in a minimal way. Details of the error will be logged but also sent via email, and I need to show a brief message to the user indicating that an error was encountered. All of this did work with Flet 0.19.0 and a custom
excepthookbut now I'm not sure how to register a handler that actually works?Docs for Page.on_error makes me think this is what I should perhaps be using instead of hacking global
excepthook, but #431 makes me think this was always meant as a more "Flet-specific" error handler and perhaps not what I would want?I also looked over https://docs.flutter.dev/testing/errors but do not yet understand enough about the Flutter side to fully grok what this means for me in Flet-land.
Screenshots / Videos
Screenshots / Video demonstration
[Upload media here]
Operating System
Linux
Operating system details
Debian 12
Flet version
0.23.2
Regression
Yes, it used to work in a previous Flet version (please specify the version in additional details)
Suggestions
I'm not 100% sure that my desired approach is the correct one; for instance
Page.on_errorseems promising instead of theexcepthookoverrides. And/or maybe a global error handler is not the best way to solve this in the first place? But it has worked okay in the past with other (non-Flet) projects..Ideally:
Page.on_errorimproved) ?Logs
Logs
[Paste your logs here]Additional details
Global threading
excepthookused to work under Flet 0.19.0Also - the above is all using Python 3.11.2
Beta Was this translation helpful? Give feedback.
All reactions