Weird startup error (revisited)

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)

Really puzzling…

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.

1 Like

Sorry missed your reply. Will try your suggestions in my error handling code.

I think you nailed it: I now think it is the Evernote Webclipper extension that is causing the problem.

I changed my error handler to this:

def error_handler(error):
  if str(error)=='Error: {}':
    print('Weird startup "unhandled exception" error occurred', type(error), str(error))
    try:
      print(error.original_error.message)
      print(error.original_error.stack)
    except:
      pass
    # temporarily re raise
    raise error
  else:
    raise error

This is the error, the message is still empty but the stack is visible:

: Error: {}
Starting MainForm
Weird startup "unhandled exception" error occurred <class 'ExternalError'> Error: {}
{}
y@safari-extension://864FBB33-6621-4903-9264-22FE9AFCFBA2/56bc8ab3/commons.js:2:2814477
fromAny@safari-extension://864FBB33-6621-4903-9264-22FE9AFCFBA2/56bc8ab3/commons.js:2:2815607
_handleResponsePromise@safari-extension://864FBB33-6621-4903-9264-22FE9AFCFBA2/56bc8ab3/commons.js:2:1087141
_handleDispatchResponse@safari-extension://864FBB33-6621-4903-9264-22FE9AFCFBA2/56bc8ab3/commons.js:2:1086916
_handleMessage@safari-extension://864FBB33-6621-4903-9264-22FE9AFCFBA2/56bc8ab3/commons.js:2:1086612
@safari-extension://864FBB33-6621-4903-9264-22FE9AFCFBA2/56bc8ab3/commons.js:2:1086413
emit@safari-extension://864FBB33-6621-4903-9264-22FE9AFCFBA2/56bc8ab3/topee-content.js:2330:17
@safari-extension://864FBB33-6621-4903-9264-22FE9AFCFBA2/56bc8ab3/topee-content.js:2129:26
MainForm: before select panel
MainForm: before update

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.

2 Likes

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):
        ...
1 Like

@stucork Thanks for the feedback again! I’’ experiment a bit with the ExternalError.

I’ll also notify Evernote, but even past experience with their helpdesk, I don’t expect too much.