Skip to content

Commit 84285b3

Browse files
authored
check that output exists (microsoft#233011)
1 parent e1e192e commit 84285b3

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3065,12 +3065,16 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
30653065
const cell = this.viewModel?.viewCells.find(vc => vc.handle === cellInfo.cellHandle);
30663066
if (cell && cell instanceof CodeCellViewModel) {
30673067
const outputIndex = cell.outputsViewModels.indexOf(output);
3068-
this._debug('update cell output', cell.handle, outputHeight);
3069-
cell.updateOutputHeight(outputIndex, outputHeight, source);
3070-
this.layoutNotebookCell(cell, cell.layoutInfo.totalHeight);
3068+
if (outputIndex > -1) {
3069+
this._debug('update cell output', cell.handle, outputHeight);
3070+
cell.updateOutputHeight(outputIndex, outputHeight, source);
3071+
this.layoutNotebookCell(cell, cell.layoutInfo.totalHeight);
30713072

3072-
if (isInit) {
3073-
this._onDidRenderOutput.fire(output);
3073+
if (isInit) {
3074+
this._onDidRenderOutput.fire(output);
3075+
}
3076+
} else {
3077+
this._debug('tried to update cell output that does not exist');
30743078
}
30753079
}
30763080
}

src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,16 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod
446446

447447
this._ensureOutputsTop();
448448

449-
if (index === 0 || height > 0) {
450-
this._outputViewModels[index].setVisible(true);
451-
} else if (height === 0) {
452-
this._outputViewModels[index].setVisible(false);
449+
try {
450+
if (index === 0 || height > 0) {
451+
this._outputViewModels[index].setVisible(true);
452+
} else if (height === 0) {
453+
this._outputViewModels[index].setVisible(false);
454+
}
455+
} catch (e) {
456+
const errorMessage = `Failed to update output height for cell ${this.handle}, output ${index}. `
457+
+ `this.outputCollection.length: ${this._outputCollection.length}, this._outputViewModels.length: ${this._outputViewModels.length}`;
458+
throw new Error(`${errorMessage}.\n Error: ${e.message}`);
453459
}
454460

455461
if (this._outputViewModels[index].visible.get() && height < 28) {

0 commit comments

Comments
 (0)