Skip to content

Commit ff35b96

Browse files
committed
Fix assumptions about error type.
1 parent e722a0d commit ff35b96

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

packages/base/src/errorwidget.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { BROKEN_FILE_SVG_ICON } from './utils';
99

1010
// create a Widget Model that captures an error object
1111
export function createErrorWidgetModel(
12-
error: Error,
12+
error: unknown,
1313
msg?: string
1414
): typeof WidgetModel {
1515
class ErrorWidget extends DOMWidgetModel {
@@ -78,12 +78,15 @@ export class ErrorWidgetView extends DOMWidgetView {
7878
}
7979

8080
export function createErrorWidgetView(
81-
error?: Error,
81+
error?: unknown,
8282
msg?: string
8383
): typeof WidgetView {
8484
return class InnerErrorWidgetView extends ErrorWidgetView {
8585
generateErrorMessage(): { msg?: string; stack: string } {
86-
return { msg, stack: String(error?.stack) };
86+
return {
87+
msg,
88+
stack: String(error instanceof Error ? error.stack : error),
89+
};
8790
}
8891
};
8992
}

packages/base/src/widget.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ export class WidgetModel extends Backbone.Model {
295295
try {
296296
this.set(state);
297297
} catch (e) {
298-
console.error(`Error setting state: ${e.message}`);
298+
console.error(
299+
`Error setting state: ${e instanceof Error ? e.message : e}`
300+
);
299301
} finally {
300302
this._state_lock = null;
301303
}

0 commit comments

Comments
 (0)