Skip to content

Commit 2d14e92

Browse files
committed
Widgetsnbextension: throw error on failure to render
1 parent c3c6fa8 commit 2d14e92

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

widgetsnbextension/src/extension.js

+26-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ require('./embed_widgets');
2121
var LuminoWidget = require('@lumino/widgets');
2222
var LuminoMessaging = require('@lumino/messaging');
2323

24+
var NOTEBOOK_VERSION_INFO = Jupyter.version.split('.');
25+
var NOTEBOOK_MAJOR = parseInt(NOTEBOOK_VERSION_INFO[0]);
26+
var NOTEBOOK_MINOR = parseInt(NOTEBOOK_VERSION_INFO[1]);
27+
var NOTEBOOK_PATCH = parseInt(NOTEBOOK_VERSION_INFO[2]);
28+
29+
var RENDER_SHOULD_THROW = (
30+
NOTEBOOK_MAJOR > 6 ||
31+
(NOTEBOOK_MAJOR == 6 && NOTEBOOK_MINOR > 4) ||
32+
(NOTEBOOK_MAJOR == 6 && NOTEBOOK_MINOR > 4 && NOTEBOOK_PATCH > 4)
33+
);
34+
2435
/**
2536
* Create a widget manager for a kernel instance.
2637
*/
@@ -123,13 +134,19 @@ function register_events(Jupyter, events, outputarea) {
123134
Jupyter.notebook.kernel &&
124135
Jupyter.notebook.kernel.widget_manager;
125136
if (!manager) {
126-
node.textContent =
127-
'Error rendering Jupyter widget: missing widget manager';
137+
var msg = 'Error rendering Jupyter widget: missing widget manager';
138+
if (RENDER_SHOULD_THROW) {
139+
throw new Error(msg);
140+
}
141+
node.textContent = msg;
128142
return;
129143
}
130144

131145
// Missing model id means the view was removed. Hide this element.
132146
if (data.model_id === '') {
147+
if (RENDER_SHOULD_THROW) {
148+
throw new Error('Jupyter Widgets model not found');
149+
}
133150
node.style.display = 'none';
134151
return;
135152
}
@@ -156,8 +173,12 @@ function register_events(Jupyter, events, outputarea) {
156173
});
157174
});
158175
} else {
159-
node.textContent =
160-
'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.';
176+
var msg = '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.';
177+
if (RENDER_SHOULD_THROW) {
178+
throw new Error(msg);
179+
}
180+
node.textContent = msg;
181+
return;
161182
}
162183
}
163184

@@ -169,6 +190,7 @@ function register_events(Jupyter, events, outputarea) {
169190
element.append(toinsert);
170191
return toinsert;
171192
};
193+
172194
// Register mime type with the output area
173195
outputarea.OutputArea.prototype.register_mime_type(MIME_TYPE, append_mime, {
174196
// An output widget could contain arbitrary user javascript

0 commit comments

Comments
 (0)