Skip to content

Commit 6afab36

Browse files
committed
fix: Enhance variable name parsing in Deepnote notebook command listener
- Updated the variable name extraction logic to use zod for safer parsing, ensuring that only valid strings are returned. - Improved error handling during JSON parsing to log errors effectively. Signed-off-by: Tomas Kislan <tomas@kislan.sk>
1 parent 0d07a20 commit 6afab36

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/notebooks/deepnote/deepnoteNotebookCommandListener.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ export function getInputBlockMetadata(blockType: InputBlockType, variableName: s
7272

7373
export function safeParseDeepnoteVariableNameFromContentJson(content: string): string | undefined {
7474
try {
75-
return JSON.parse(content)['deepnote_variable_name'];
75+
const variableNameResult = z.string().safeParse(JSON.parse(content)['deepnote_variable_name']);
76+
return variableNameResult.success ? variableNameResult.data : undefined;
7677
} catch (error) {
7778
logger.error('Error parsing deepnote variable name from content JSON', error);
7879
return undefined;

0 commit comments

Comments
 (0)