n-riesco / ijavascript

IJavascript is a javascript kernel for the Jupyter notebook
Other
2.19k stars 185 forks source link

Throwing an error without a traceback causes the corruption of a Jupyter notebook #230

Closed apowers313 closed 3 years ago

apowers313 commented 3 years ago

To reproduce: image

Result: image

In the console:

[E 22:07:57.287 NotebookApp] Notebook JSON is invalid: '' is not of type 'array'

    Failed validating 'type' in error['properties']['traceback']:

    On instance['cells'][0]['outputs'][0]['traceback']:
    ''

Notebook is:

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "number",
     "evalue": "3",
     "output_type": "error",
     "traceback": ""
    }
   ],
   "source": [
    "Promise.reject(3)"
   ]
  }
 ],
 "metadata": {
    // stuff
  }
}
n-riesco commented 3 years ago

I can reproduce the issue.

I've also noticed this only happens with synchronous cells. For example, the equivalent code for an asynchronous cell works as expected:

$$.async();
$$.done(Promise.reject(3));

Screenshot from 2020-12-11 09-17-53


More info on asynchronous cells here.

n-riesco commented 3 years ago
$$.async();\n$$.done(Promise.reject(3));
NEL: SERVER: RECEIVED: [ 'run', '$$.async();\n$$.done(Promise.reject(3));', 1 ]
NEL: SERVER: SEND: { mime: { 'text/plain': 'Promise { <rejected> 3 }' },
  end: true,
  id: 1 }
NEL: SESSION: RECEIVED: { mime: { 'text/plain': 'Promise { <rejected> 3 }' },
  end: true,
  id: 1 }
JMP: SOCKET: SEND: Message {
  idents: 
   [ <Buffer 46 46 41 35 41 33 30 34 46 31 37 33 34 35 45 30 41 45 44 30 31 44 35 39 31 39 32 43 30 38 33 44> ],
  header: 
   { msg_id: 'a6c1e94f-1b20-48fd-a96f-8041a389c8f1',
     username: 'username',
     session: 'FFA5A304F17345E0AED01D59192C083D',
     msg_type: 'execute_reply',
     version: '5.2' },
  parent_header: 
   { msg_id: '87BCA63DBAB04430870ECA2D8D30325B',
     username: 'username',
     session: 'FFA5A304F17345E0AED01D59192C083D',
     msg_type: 'execute_request',
     version: '5.2',
     date: '2020-12-11T09:30:55.581042Z' },
  metadata: {},
  content: 
   { status: 'ok',
     execution_count: 1,
     payload: [],
     user_expressions: {} },
  buffers: [] }
Promise.reject(3);
NEL: SERVER: RECEIVED: [ 'run', 'Promise.reject(3);', 2 ]
NEL: SERVER: SEND: { error: { ename: 'number', evalue: '3', traceback: '' },
  end: true,
  id: 2 }
NEL: SESSION: RECEIVED: { error: { ename: 'number', evalue: '3', traceback: '' },
  end: true,
  id: 2 }
JMP: SOCKET: SEND: Message {
  idents: 
   [ <Buffer 46 46 41 35 41 33 30 34 46 31 37 33 34 35 45 30 41 45 44 30 31 44 35 39 31 39 32 43 30 38 33 44> ],
  header: 
   { msg_id: 'd32b0150-38ed-4166-ad0c-b69c518962e2',
     username: 'username',
     session: 'FFA5A304F17345E0AED01D59192C083D',
     msg_type: 'execute_reply',
     version: '5.2' },
  parent_header: 
   { msg_id: '9757B5EBE2AE451B9B22BA25942E3261',
     username: 'username',
     session: 'FFA5A304F17345E0AED01D59192C083D',
     msg_type: 'execute_request',
     version: '5.2',
     date: '2020-12-11T09:38:01.635951Z' },
  metadata: {},
  content: 
   { status: 'error',
     execution_count: 2,
     ename: 'number',
     evalue: '3',
     traceback: '' },
  buffers: [] }
throw new Error(3);
NEL: SERVER: RECEIVED: [ 'run', 'throw new Error(3);', 1 ]
NEL: SERVER: SEND: { error: 
   { ename: 'Error',
     evalue: '3',
     traceback: 
      [ 'evalmachine.<anonymous>:1',
        'throw new Error(3);',
        '^',
        '',
        'Error: 3',
        '    at evalmachine.<anonymous>:1:7',
        '    at ContextifyScript.Script.runInThisContext (vm.js:50:33)',
        '    at Object.runInThisContext (vm.js:139:38)',
        '    at run ([eval]:1054:15)',
        '    at onRunRequest ([eval]:888:18)',
        '    at onMessage ([eval]:848:13)',
        '    at emitTwo (events.js:126:13)',
        '    at process.emit (events.js:214:7)',
        '    at emit (internal/child_process.js:772:12)',
        '    at _combinedTickCallback (internal/process/next_tick.js:141:11)' ] },
  end: true,
  id: 1 }
NEL: SESSION: RECEIVED: { error: 
   { ename: 'Error',
     evalue: '3',
     traceback: 
      [ 'evalmachine.<anonymous>:1',
        'throw new Error(3);',
        '^',
        '',
        'Error: 3',
        '    at evalmachine.<anonymous>:1:7',
        '    at ContextifyScript.Script.runInThisContext (vm.js:50:33)',
        '    at Object.runInThisContext (vm.js:139:38)',
        '    at run ([eval]:1054:15)',
        '    at onRunRequest ([eval]:888:18)',
        '    at onMessage ([eval]:848:13)',
        '    at emitTwo (events.js:126:13)',
        '    at process.emit (events.js:214:7)',
        '    at emit (internal/child_process.js:772:12)',
        '    at _combinedTickCallback (internal/process/next_tick.js:141:11)' ] },
  end: true,
  id: 1 }
throw 3;
NEL: SERVER: SEND: { error: { ename: 'number', evalue: '3', traceback: '' },
  end: true,
  id: 2 }
NEL: SESSION: RECEIVED: { error: { ename: 'number', evalue: '3', traceback: '' },
  end: true,
  id: 2 }
JMP: SOCKET: SEND: Message {
  idents: 
   [ <Buffer 33 43 34 37 42 36 32 36 34 32 34 39 34 33 39 42 39 35 32 41 45 41 36 32 43 33 36 30 30 35 44 31> ],
  header: 
   { msg_id: 'd4085f7a-ec79-45e0-a3dd-3cffcfbe2bb6',
     username: 'username',
     session: '3C47B6264249439B952AEA62C36005D1',
     msg_type: 'execute_reply',
     version: '5.2' },
  parent_header: 
   { msg_id: '6745AC2B1EEA405A87C387A31FC1CE1C',
     username: 'username',
     session: '3C47B6264249439B952AEA62C36005D1',
     msg_type: 'execute_request',
     version: '5.2',
     date: '2020-12-11T09:49:58.351887Z' },
  metadata: {},
  content: 
   { status: 'error',
     execution_count: 2,
     ename: 'number',
     evalue: '3',
     traceback: '' },
  buffers: [] }
n-riesco commented 3 years ago

This has been a fun issue to debug. It turns out the issue is actually throwing an error without a traceback causes the corruption of a jupyter notebook! The fix is just a one-liner. I'll push the change ~and see if the news about Travis are as bad as they say~ :fearful: (slow but working).