Skip to content

Commit ed5329d

Browse files
committed
fix: Enhance error handling for big number metadata parsing and improve chart big number renderer logic
1 parent 628ab6e commit ed5329d

File tree

5 files changed

+35
-29
lines changed

5 files changed

+35
-29
lines changed

src/kernels/execution/cellExecution.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,18 @@ export class CellExecution implements ICellExecution, IDisposable {
420420
const deepnoteBlock = createBlockFromPocket(cellData, this.cell.index);
421421

422422
if (deepnoteBlock.type === 'big-number') {
423-
deepnoteBlock.metadata = {
424-
...deepnoteBlock.metadata,
425-
...DeepnoteBigNumberMetadataSchema.parse(JSON.parse(deepnoteBlock.content || '{}'))
426-
};
423+
try {
424+
deepnoteBlock.metadata = {
425+
...deepnoteBlock.metadata,
426+
...DeepnoteBigNumberMetadataSchema.parse(JSON.parse(deepnoteBlock.content || '{}'))
427+
};
428+
} catch (ex) {
429+
logger.error(
430+
`Cell execution failed to parse big number metadata, for cell Index ${this.cell.index}`,
431+
ex
432+
);
433+
return this.completedWithErrors(ex);
434+
}
427435
}
428436

429437
// Use createPythonCode to generate code with table state already included

src/notebooks/deepnote/converters/chartBigNumberBlockConverter.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ suite('ChartBigNumberBlockConverter', () => {
394394
assert.strictEqual(block.content, '');
395395
assert.strictEqual(block.metadata?.deepnote_big_number_title, 'new title');
396396
assert.strictEqual(block.metadata?.existing, 'value');
397-
assert.isUndefined(block.metadata?.[DEEPNOTE_VSCODE_RAW_CONTENT_KEY]);
397+
assert.doesNotHaveAnyKeys(block.metadata, [DEEPNOTE_VSCODE_RAW_CONTENT_KEY]);
398398
});
399399

400400
test('handles empty content', () => {

src/notebooks/deepnote/deepnoteDataConverter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export class DeepnoteDataConverter {
306306
// Plain text as fallback (always last)
307307
if (data['text/plain']) {
308308
let mimeType = 'text/plain';
309-
if (blockType === 'big-number') {
309+
if (blockType === 'big-number' && !(CHART_BIG_NUMBER_MIME_TYPE in data)) {
310310
mimeType = CHART_BIG_NUMBER_MIME_TYPE;
311311
}
312312
items.push(NotebookCellOutputItem.text(data['text/plain'] as string, mimeType));

src/webviews/webview-side/chart-big-number-renderer/ChartBigNumberOutputRenderer.tsx

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,11 @@ export function ChartBigNumberOutputRenderer({
1010
metadata: DeepnoteBigNumberMetadata;
1111
}) {
1212
// TODO: either remove or handle here .. currently handled in the parent
13-
const hasErrors = false;
14-
1513
const title = useMemo(() => {
16-
if (hasErrors) {
17-
return 'Not defined';
18-
}
19-
2014
return output.title || 'Title';
21-
}, [output.title, hasErrors]);
15+
}, [output.title]);
2216

2317
const value = useMemo(() => {
24-
if (hasErrors) {
25-
return 'N/A';
26-
}
27-
2818
if (!output.value) {
2919
return 'Value';
3020
}
@@ -36,13 +26,9 @@ export function ChartBigNumberOutputRenderer({
3626
}
3727

3828
return formatValue(parsedValue, metadata.deepnote_big_number_format ?? 'number');
39-
}, [hasErrors, output.value, metadata.deepnote_big_number_format]);
29+
}, [output.value, metadata.deepnote_big_number_format]);
4030

4131
const comparisonValue = useMemo(() => {
42-
if (hasErrors) {
43-
return undefined;
44-
}
45-
4632
if (!output.comparisonValue) {
4733
return undefined;
4834
}
@@ -75,13 +61,9 @@ export function ChartBigNumberOutputRenderer({
7561
}
7662

7763
return parsedValue - parsedComparisonValue;
78-
}, [hasErrors, metadata.deepnote_big_number_comparison_type, output.comparisonValue, output.value]);
64+
}, [metadata.deepnote_big_number_comparison_type, output.comparisonValue, output.value]);
7965

8066
const formattedComparisonValue = useMemo(() => {
81-
if (hasErrors) {
82-
return '-';
83-
}
84-
8567
if (comparisonValue == null) {
8668
return '-';
8769
}
@@ -93,7 +75,7 @@ export function ChartBigNumberOutputRenderer({
9375
}
9476

9577
return formatValue(comparisonValue, metadata.deepnote_big_number_format ?? 'number');
96-
}, [comparisonValue, metadata.deepnote_big_number_format, hasErrors, metadata.deepnote_big_number_comparison_type]);
78+
}, [comparisonValue, metadata.deepnote_big_number_format, metadata.deepnote_big_number_comparison_type]);
9779

9880
const changeDirection = useMemo(() => {
9981
if (comparisonValue == null) {

src/webviews/webview-side/chart-big-number-renderer/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,24 @@ export const activate: ActivationFunction = (_context: RendererContext<unknown>)
4141
}
4242
},
4343

44-
disposeOutputItem(_id?: string) {
44+
disposeOutputItem(id?: string) {
4545
// Cleanup if needed
46+
if (id == null) {
47+
return;
48+
}
49+
const element = document.getElementById(id);
50+
if (element == null) {
51+
return;
52+
}
53+
const roots = element.getElementsByTagName('div');
54+
for (let i = 0; i < roots.length; i++) {
55+
const root = roots.item(i);
56+
if (root == null) {
57+
continue;
58+
}
59+
ReactDOM.unmountComponentAtNode(root);
60+
element.removeChild(root);
61+
}
4662
}
4763
};
4864
};

0 commit comments

Comments
 (0)