When loading my app in the browser I often get an unhandled exception. When looking at the logs I see just
: Error: {}
If it occurs it is always at app startup. Not when the app is reloaded in the browser (existing session?).
I have posted about this error before, and some javascript library was blamed (what else is JS good for). However this app has no dependencies beyond an Iframe component.
I am able to catch the error with a custom error handler:
def error_handler(error):
if str(error)=='Error: {}':
print('Weird startup "unhandled exception" error occurred', str(error))
else:
raise error
set_default_error_handling(error_handler)
class MainForm(MainFormTemplate):
def __init__(self, **properties):
print('Starting MainForm')
# Set Form properties and Data Bindings.
self.init_components(**properties)
Perhaps this has to do with some of the features that have been added to the app? I think some features could cause starting services / processes in the background during initial startup possibly a specific feature throws some error?
The app does nothing at startup. The code that you see in my post is the main form. The error happens before the MainForm’s init.
Also as said the app has no dependencies. The app uses uplink code, but that is called later in the app.
Have you tried seeing if you can reproduce the error in an incognito window?
That’ll eliminate the possibility that a browser extension is the cause.
Otherwise - a reproducible clone with steps including browser/os would be handy.
It definitely seems like a javascript error being thrown and it doesn’t seem like an anvil source code error.
If it’s an ExternalError you could try doing error.original_error.message or error.original_error.stack, which may expose some more information about the error.
Observations;
Error happens only in Safari with the Evernote extension enabled.
Error happens only at app startup in new browser window.
Error happens not always.
So it seems like some race condition at startup to me. Does not surprise me that it is the Evernote extension, EN being the garbage that it is.
I had a look in the web inspector. It seems the offending error is “unhandled promise rejection” thrown by Evernote code that for some reason is caught in Anvil.
Anvil wouldn’t be able to distinguish whether this was an error from a javascript library you intended to use, say from Native Libraries, or in this case a browser extension.
If it was from a javascript library you were using, you’d probably want to know about these errors - otherwise they’d just be silently ignored.
You could decide to ignore ExternalErrors in your custom error handler here and just log them.
Remember you can now catch all ExternalErrors with
from anvil.js import ExternalError
def error_handler(e):
if isinstance(e, ExternalError):
...