jupyter-server / kernel_gateway

Jupyter Kernel Gateway
http://jupyter-kernel-gateway.readthedocs.org/en/latest/
Other
504 stars 130 forks source link

Kernel Gateway returns Messed Up Error Traceback #296

Closed bashterm closed 6 years ago

bashterm commented 6 years ago

I've been working on a standalone angular app that utilizes the @jupyterlab/services package in order to interact with the kernel gateway.

Connection works and execution works, but when an error occurs the traceback array comes through very messed up. I'm not sure what the problem is. The result looks like this:

{
  "header": {
    "version": "5.3",
    "date": "2018-07-24T15:06:22.625374Z",
    "session": "3a132ba9-ab67351385c53eaa6514b2c0",
    "username": "username",
    "msg_type": "error",
    "msg_id": "2908ae80-2cf2947f3bff2e2d516214bf"
  },
  "msg_id": "2908ae80-2cf2947f3bff2e2d516214bf",
  "msg_type": "error",
  "parent_header": {
    "username": "",
    "version": "5.2",
    "session": "f3a98c1a6e48718af1764a104628b4ab",
    "msg_id": "398575ac5c19294b161d67da44ef00ac",
    "msg_type": "execute_request",
    "date": "2018-07-24T15:06:22.621538Z"
  },
  "metadata": {},
  "content": {
    "traceback": [
      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-1-8dc86dcd4f82>\"\u001b[0;36m, line \u001b[0;32m7\u001b[0m\n\u001b[0;31m    print(y)\u001b[0m\n\u001b[0m        ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
    ],
    "ename": "SyntaxError",
    "evalue": "invalid syntax (<ipython-input-1-8dc86dcd4f82>, line 7)"
  },
  "buffers": [],
  "channel": "iopub"
}

It seems to be an encoding issue, but I can't figure out how to fix it.

Thanks for any help

kevin-bates commented 6 years ago

Hello,

I believe those codes are color codes used in syntax hilighting and are a function of the underlying kernel (e.g., ipython). Using Jupyter Enterprise Gateway, which derives from JKG, I just introduced a syntax error and got back the following...

  'content': {'ename': 'SyntaxError',
             'engine_info': {'engine_id': -1,
                             'engine_uuid': '007b1c2b-2a4b-41a9-afe3-22bc3851fbc1',
                             'method': 'execute'},
             'evalue': 'unexpected EOF while parsing '
                       '(<ipython-input-1-50c06c4f46d7>, line 1)',
             'execution_count': 0,
             'payload': [],
             'status': 'error',
             'traceback': ['\x1b[0;36m  File '
                           '\x1b[0;32m"<ipython-input-1-50c06c4f46d7>"\x1b[0;36m, '
                           'line \x1b[0;32m1\x1b[0m\n'
                           "\x1b[0;31m    print('Hello World'\x1b[0m\n"
                           '\x1b[0m                       ^\x1b[0m\n'
                           '\x1b[0;31mSyntaxError\x1b[0m\x1b[0;31m:\x1b[0m '
                           'unexpected EOF while parsing\n'],
             'user_expressions': {}},

which produces this output in a notebook...

screen shot 2018-07-25 at 11 20 45 am

However, if I first issue #colors NoColor, then terminal colors are disabled and I get back this...

 'content': {'ename': 'SyntaxError',
             'engine_info': {'engine_id': -1,
                             'engine_uuid': '0b254f3d-552c-46c1-90d5-389adee92e44',
                             'method': 'execute'},
             'evalue': 'unexpected EOF while parsing '
                       '(<ipython-input-1-50c06c4f46d7>, line 1)',
             'execution_count': 0,
             'payload': [],
             'status': 'error',
             'traceback': ['  File "<ipython-input-1-50c06c4f46d7>", line 1\n'
                           "    print('Hello World'\n"
                           '                       ^\n'
                           'SyntaxError: unexpected EOF while parsing\n'],
             'user_expressions': {}},

I'd expect similar results using a straight (non-gateway) notebook configuration as well.

I hope this helps.

bashterm commented 6 years ago

Thank you so much. I would never have figured that out on my own. I really appreciate it.