Skip to content

Commit 92c805d

Browse files
committed
Make metadata access safer at runtime
The `!` operator is a type assertion that the attribute is not null, but does nothing at runtime to ensure this is the case. I haven't yet found reproduction steps for this failure, but I encountered a case where accessing `model!.sharedModel` threw an error. This commit adds optional chaining operators, which do provide protection at runtime.
1 parent 62b57c3 commit 92c805d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class JupyterlabNotebookCodeFormatter extends JupyterlabCodeFormatter {
9898
}
9999

100100
const metadata =
101-
this.notebookTracker.currentWidget.content.model!.sharedModel.metadata;
101+
this.notebookTracker.currentWidget.content.model?.sharedModel?.metadata;
102102

103103
if (!metadata) {
104104
return null;

0 commit comments

Comments
 (0)