Skip to content

Commit dba8e05

Browse files
hmtosiederign
andauthored
Issue 451 - fixing errors that occur when opening and closing notebooks (#496)
* initial changes developed with cursor * no pop up * no modal, toast appears, error logged in console * add error location to toast * print stacktrace for nonextension errors * fix failing gha * switch to built-in jupyter notification api * finish cleaning up one-off toast method * Revert "finish cleaning up one-off toast method" This reverts commit 2dbafba. * remove one-off toast method from other files * revert index.css to state from main * update string handling to identify labextension errors * make error handling more robust * edit error message to be agnostic to stack trace format * fix typo --------- Co-authored-by: Eder Ignatowicz <[email protected]>
1 parent 0e10637 commit dba8e05

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

labextension/src/lib/RPCUtils.tsx

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,55 @@ import { NotebookPanel } from '@jupyterlab/notebook';
1919
import { Kernel } from '@jupyterlab/services';
2020
import NotebookUtils from './NotebookUtils';
2121
import { isError, IError, IOutput } from '@jupyterlab/nbformat';
22+
import { Notification } from '@jupyterlab/apputils';
2223

2324
export const globalUnhandledRejection = async (event: any) => {
24-
// console.error(event.reason);
25+
console.error(event.reason);
2526
if (event.reason instanceof BaseError) {
2627
console.error(event.reason.message, event.reason.error);
2728
event.reason.showDialog().then();
2829
} else {
29-
showError(
30-
'An unexpected error has occurred',
31-
'JS',
32-
`${event.reason.name}: ${event.reason.message}`,
33-
'Please see the console for more information',
34-
true,
35-
).then();
30+
// pull the stacktrace for the unhandled error
31+
const errorStack = event.reason.stack;
32+
// isolate the segments
33+
const stackLines = errorStack.split('\n');
34+
// create alert string
35+
const alert_string = 'Unhandled Error'
36+
// call the toast pop up
37+
if (errorStack.includes('lab/extensions/')){
38+
// if the error is caused by a jupyterlab extension, try to isolate the extension name
39+
const extensionName = getExtensionName(stackLines)
40+
Notification.error(`An unhandled error has been thrown.`, {
41+
actions: [
42+
{ label: 'Details', callback: () => NotebookUtils.showMessage(alert_string,
43+
["An unhandled error was thrown from:",
44+
extensionName,
45+
"Please see console for more details."
46+
]) }
47+
],
48+
autoClose: 3000
49+
});
50+
} else {
51+
Notification.error(`An unhandled error has been thrown.`, {
52+
actions: [
53+
{ label: 'Details', callback: () => NotebookUtils.showMessage(alert_string,
54+
["Please see console for more details."]) }
55+
],
56+
autoClose: 3000
57+
});
58+
}
3659
}
3760
};
3861

62+
function getExtensionName(stackLines: Array<string>){
63+
const urlSplit = stackLines.slice(1,2).toString();
64+
const extensionSplit = urlSplit.split('@').slice(1,2).toString();
65+
const extensionParts = extensionSplit.split('/');
66+
extensionParts.pop();
67+
const extensionName = extensionParts.join('/');
68+
return extensionName || 'unknown Jupyterlab extension';
69+
}
70+
3971
export interface IRPCError {
4072
rpc: string;
4173
code: number;

0 commit comments

Comments
 (0)