Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling uncaught promise rejects in Jupyter widgets package #81

Open
vivek1729 opened this issue Sep 1, 2021 · 2 comments
Open

Handling uncaught promise rejects in Jupyter widgets package #81

vivek1729 opened this issue Sep 1, 2021 · 2 comments

Comments

@vivek1729
Copy link
Collaborator

Hey folks, we are leveraging the @nteract/jupyter-widgets to support ipywidgets in our notebooks experience. I noticed that while rendering some notebooks that contain widget reference(s), we start seeing errors like the following on the console:

image

Cause

On a deeper investigation, the error is coming from this line in the WidgetDisplay component:

const model = await modelById(model_id);

I believe the component tries to fetch the model state from the kernel and if the state is not found there is a promise rejection that is uncaught in WidgetDisplay. This seems to be printing out this uncaught exceptions on to the console.

Proposal

I think the line I highlighted above with modelById should be surrounded by a try-catch block.

However, I wanted to understand what is the guidance on routing errors when caught? From this discussion thread, it seems like we might be able to dispatch an action so that hosts like us can then intercept these actions in our own epics if we need to log those errors upstream. However, I couldn't locate which action should we be relying on. Would you be able to provide some guidance here?

Thanks!

@vivek1729 vivek1729 changed the title Catching errors when fetching model state from Kernel Handling uncaught promise rejects in Jupyter widgets package Sep 1, 2021
@captainsafia
Copy link
Member

Ah, this is an interesting one.

Instead of retroactively catching the exceptions and trying to log, can we be defensive and check for some required state before trying to get the model by the ideal. For example, we can try to make this selector:

let model = selectors.modelById(state, { commId: model_id });

A little more resilient.

I'm proposing this because the logging question opens up a can of worms that is still unresolved as mentioned above.

@vivek1729
Copy link
Collaborator Author

The failure seems to be happening in the following section where we try to request some state from the kernel:

let request_state_response = await request_state(
currentKernel,
model_id
);

Looking at the code comment, the request from kernel seems to be a fallback when we are unable to find the model state in the redux store. The selector already has returned null, I am not sure if there is any other info in the redux state which would help us avoid the kernel request check. I am not too familiar with the widget protocol so I don't fully understand the intent behind requesting the state from kernel when model couldn't be find in redux state.

We can potentially check for failure in this section and return null when the kernel is unable to find the model state. This way the modelById method won't throw an exception as we would cover both the success and failure case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants