Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (index < 0 || index >= notebook.model.cells.length) {
throw new Error('Cell index out of range.');
}
const cell: ICellModel = notebook.model.cells.get(index);
if (!isCodeCellModel(cell)) {
throw new Error('cell is not a code cell.');
}
if (cell.outputs.length < 1) {
return null;
}
const out = cell.outputs.toJSON().pop();
if (isExecuteResult(out)) {
return out.data['text/plain'];
}
if (isStream(out)) {
return out.text;
}
if (isError(out)) {
const errData: IError = out;
throw new Error(
`Code resulted in errors. Error name: ${errData.ename}.\nMessage: ${errData.evalue}.`,
);
}
}