Skip to content

Commit

Permalink
Widgetsnbextension: throw error on failure to render
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Sep 21, 2021
1 parent c3c6fa8 commit 7306b8e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions widgetsnbextension/src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,12 @@ function register_events(Jupyter, events, outputarea) {
Jupyter.notebook.kernel &&
Jupyter.notebook.kernel.widget_manager;
if (!manager) {
node.textContent =
'Error rendering Jupyter widget: missing widget manager';
return;
throw new Error('Error rendering Jupyter widget: missing widget manager');
}

// Missing model id means the view was removed. Hide this element.
if (data.model_id === '') {
node.style.display = 'none';
return;
throw new Error('Jupyter Widgets model not found');
}

var model = manager.get_model(data.model_id);
Expand All @@ -156,8 +153,9 @@ function register_events(Jupyter, events, outputarea) {
});
});
} else {
node.textContent =
'A Jupyter widget could not be displayed because the widget state could not be found. This could happen if the kernel storing the widget is no longer available, or if the widget state was not saved in the notebook. You may be able to create the widget by running the appropriate cells.';
throw new Error(
'A Jupyter widget could not be displayed because the widget state could not be found. This could happen if the kernel storing the widget is no longer available, or if the widget state was not saved in the notebook. You may be able to create the widget by running the appropriate cells.'
);
}
}

Expand All @@ -169,6 +167,7 @@ function register_events(Jupyter, events, outputarea) {
element.append(toinsert);
return toinsert;
};

// Register mime type with the output area
outputarea.OutputArea.prototype.register_mime_type(MIME_TYPE, append_mime, {
// An output widget could contain arbitrary user javascript
Expand Down

0 comments on commit 7306b8e

Please sign in to comment.