| 356 | } |
| 357 | |
| 358 | export function translateCellErrorOutput(output: NotebookCellOutput): nbformat.IError { |
| 359 | // it should have at least one output item |
| 360 | const firstItem = output.items[0]; |
| 361 | // Bug in VS Code. |
| 362 | if (!firstItem.data) { |
| 363 | return { |
| 364 | output_type: 'error', |
| 365 | ename: '', |
| 366 | evalue: '', |
| 367 | traceback: [] |
| 368 | }; |
| 369 | } |
| 370 | const originalError: undefined | nbformat.IError = output.metadata?.originalError; |
| 371 | const value: Error = JSON.parse(new TextDecoder().decode(firstItem.data)); |
| 372 | return { |
| 373 | output_type: 'error', |
| 374 | ename: value.name, |
| 375 | evalue: value.message, |
| 376 | // VS Code needs an `Error` object which requires a `stack` property as a string. |
| 377 | // Its possible the format could change when converting from `traceback` to `string` and back again to `string` |
| 378 | // When .NET stores errors in output (with their .NET kernel), |
| 379 | // stack is empty, hence store the message instead of stack (so that somethign gets displayed in ipynb). |
| 380 | traceback: originalError?.traceback || splitMultilineString(value.stack || value.message || '') |
| 381 | }; |
| 382 | } |
| 383 | const textDecoder = new TextDecoder(); |
| 384 | const textMimeTypes = ['text/plain', 'text/markdown', CellOutputMimeTypes.stderr, CellOutputMimeTypes.stdout]; |
| 385 | function convertOutputMimeToJupyterOutput(mime: string, value: Uint8Array) { |