jupyterlab-lsp icon indicating copy to clipboard operation
jupyterlab-lsp copied to clipboard

Improve exception handling: print culprit line on parsing stdio parsing error

Open brianhmj opened this issue 2 years ago • 8 comments

Description

I am trying to use jupyterlab-lsp extension for jupyterlab. I keep running in to "tornado.httputil.HTTPInputError: no colon in header line" error that causes the ServerApp LSP to throw a "couldn't enqueue message" error, causing all LSP extensions to stop working. I am currently using jupyterlab-lsp==3.10.0 and pylsp language server. I have downloaded all optional providers. I tried deleting and reinstalling all dependencies and packages and it still throws the same error when writing/saving anything on a jupyter notebook (ipynb) opened in jupyterLab.

For some more information, I am using... Python 3.10.2 pip 22.0.3 jupyterlab 3.2.9 jupyter-lsp 1.5.1 jupyterlab-lsp 3.10.0 python-lsp-server 1.3.3

Google Chrome 98.0.4758.82 (Official Build) (64-bit) Windows 11 Home, OS build 22000.493, 64-bit operating system, x64-based processor

Reproduce

To Reproduce the problem, download all the packages and dependencies. Run jupyterlab and type things in a new notebook.

Expected behavior

I don't really understand where the errors are coming from.

Context

Python 3.10.2 pip 22.0.3 jupyterlab 3.2.9 jupyter-lsp 1.5.1 jupyterlab-lsp 3.10.0 python-lsp-server 1.3.3

Google Chrome 98.0.4758.82 (Official Build) (64-bit) Windows 11 Home, OS build 22000.493, 64-bit operating system, x64-based processor

Required: installed server extensions
config dir: C:\Users\bribr\AppData\Local\Programs\Python\Python310\etc\jupyter
    jupyter_lsp enabled
    - Validating...
      jupyter_lsp 1.5.1 ok
    jupyterlab enabled
    - Validating...
      jupyterlab 3.2.9 ok
Required: installed lab extensions
JupyterLab v3.2.9
C:\Users\bribr\AppData\Local\Programs\Python\Python310\share\jupyter\labextensions
        @krassowski/jupyterlab-lsp v3.10.0 enabled ok (python, jupyterlab-lsp)
Troubleshoot Output
$PATH:
        C:\WINDOWS\system32
        C:\WINDOWS
        C:\WINDOWS\System32\Wbem
        C:\WINDOWS\System32\WindowsPowerShell\v1.0\
        C:\WINDOWS\System32\OpenSSH\
        C:\Program Files (x86)\Diffusion Toolkit
        C:\Program Files\Git\cmd
        C:\Program Files\nodejs\
        C:\Program Files\MATLAB\R2021b\runtime\win64
        C:\Program Files\MATLAB\R2021b\bin
        C:\Users\bribr\AppData\Roaming\Programs\Python\Python310\Scripts
        C:\Users\bribr\AppData\Local\Programs\Python\Python310\Scripts\
        C:\Users\bribr\AppData\Local\Programs\Python\Python310\
        C:\Users\bribr\.cargo\bin
        C:\Users\bribr\AppData\Local\Microsoft\WindowsApps
        C:\Users\bribr\AppData\Local\Programs\Microsoft VS Code\bin
        C:\Users\bribr\AppData\Roaming\npm
        C:\Users\bribr\AppData\Local\nvs\
        C:\Users\bribr\.espressif/tools/xtensa-esp32-elf-clang/esp-12.0.1-20210914-x86_64-pc-windows-msvc/bin/

sys.path: C:\Users\bribr\AppData\Local\Programs\Python\Python310\Scripts\jupyter-troubleshoot.EXE C:\Users\bribr\AppData\Local\Programs\Python\Python310\python310.zip C:\Users\bribr\AppData\Local\Programs\Python\Python310\DLLs C:\Users\bribr\AppData\Local\Programs\Python\Python310\lib C:\Users\bribr\AppData\Local\Programs\Python\Python310 C:\Users\bribr\AppData\Roaming\Python\Python310\site-packages C:\Users\bribr\AppData\Roaming\Python\Python310\site-packages\win32 C:\Users\bribr\AppData\Roaming\Python\Python310\site-packages\win32\lib C:\Users\bribr\AppData\Roaming\Python\Python310\site-packages\Pythonwin C:\Users\bribr\AppData\Local\Programs\Python\Python310\lib\site-packages C:\Users\bribr\AppData\Local\Programs\Python\Python310\lib\site-packages\win32 C:\Users\bribr\AppData\Local\Programs\Python\Python310\lib\site-packages\Pythonwin

sys.executable: C:\Users\bribr\AppData\Local\Programs\Python\Python310\python.exe

sys.version: 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)]

platform.platform(): Windows-10-10.0.22000-SP0

where jupyter: C:\Users\bribr\AppData\Local\Programs\Python\Python310\Scripts\jupyter.exe

pip list: Package Version -------------------- --------- anyio 3.5.0 argon2-cffi 21.3.0 argon2-cffi-bindings 21.2.0 astroid 2.9.3 asttokens 2.0.5 attrs 21.4.0 autopep8 1.6.0 Babel 2.9.1 backcall 0.2.0 beniget 0.4.1 black 22.1.0 bleach 4.1.0 certifi 2021.10.8 cffi 1.15.0 charset-normalizer 2.0.12 click 8.0.3 colorama 0.4.4 debugpy 1.5.1 decorator 5.1.1 defusedxml 0.7.1 Deprecated 1.2.13 entrypoints 0.4 executing 0.8.2 flake8 4.0.1 frilouz 0.0.2 gast 0.5.3 idna 3.3 ipykernel 6.9.0 ipython 8.0.1 ipython-genutils 0.2.0 isort 5.10.1 jedi 0.18.1 Jinja2 3.0.3 json5 0.9.6 jsonschema 4.4.0 jupyter-client 7.1.2 jupyter-core 4.9.1 jupyter-lsp 1.5.1 jupyter-server 1.13.5 jupyterlab 3.2.9 jupyterlab-lsp 3.10.0 jupyterlab-pygments 0.1.2 jupyterlab-server 2.10.3 lazy-object-proxy 1.7.1 MarkupSafe 2.0.1 matplotlib-inline 0.1.3 mccabe 0.6.1 memestra 0.2.1 mistune 0.8.4 mypy-extensions 0.4.3 nbclassic 0.3.5 nbclient 0.5.11 nbconvert 6.4.2 nbformat 5.1.3 nest-asyncio 1.5.4 notebook 6.4.8 packaging 21.3 pandocfilters 1.5.0 parso 0.8.3 pathspec 0.9.0 pickleshare 0.7.5 pip 22.0.3 platformdirs 2.5.0 pluggy 1.0.0 prometheus-client 0.13.1 prompt-toolkit 3.0.28 pure-eval 0.2.2 pycodestyle 2.8.0 pycparser 2.21 pydocstyle 6.1.1 pyflakes 2.4.0 Pygments 2.11.2 pylint 2.12.2 pyls-memestra 0.0.15 pyparsing 3.0.7 pyrsistent 0.18.1 python-dateutil 2.8.2 python-lsp-jsonrpc 1.0.0 python-lsp-server 1.3.3 pytz 2021.3 pywin32 303 pywinpty 1.1.6 PyYAML 6.0 pyzmq 22.3.0 requests 2.27.1 rope 0.22.0 Send2Trash 1.8.0 setuptools 58.1.0 six 1.16.0 sniffio 1.2.0 snowballstemmer 2.2.0 stack-data 0.2.0 terminado 0.13.1 testpath 0.5.0 toml 0.10.2 tomli 2.0.1 tornado 6.1 traitlets 5.1.1 ujson 5.1.0 urllib3 1.26.8 wcwidth 0.2.5 webencodings 0.5.1 websocket-client 1.2.3 wrapt 1.13.3 yapf 0.32.0

Command Line Output
[I 2022-02-14 20:01:45.319 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2022-02-14 20:01:45.331 ServerApp] jupyterlab | extension was successfully linked.
[I 2022-02-14 20:01:45.724 ServerApp] nbclassic | extension was successfully linked.
[I 2022-02-14 20:01:45.767 ServerApp] nbclassic | extension was successfully loaded.
[I 2022-02-14 20:01:45.824 ServerApp] Skipped non-installed server(s): bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyright, python-language-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server
[I 2022-02-14 20:01:45.935 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2022-02-14 20:01:45.937 LabApp] JupyterLab extension loaded from C:\Users\bribr\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyterlab
[I 2022-02-14 20:01:45.937 LabApp] JupyterLab application directory is C:\Users\bribr\AppData\Local\Programs\Python\Python310\share\jupyter\lab
[I 2022-02-14 20:01:45.942 ServerApp] jupyterlab | extension was successfully loaded.
[I 2022-02-14 20:01:45.943 ServerApp] Serving notebooks from local directory: C:\Users\bribr
[I 2022-02-14 20:01:45.943 ServerApp] Jupyter Server 1.13.5 is running at:
[I 2022-02-14 20:01:45.943 ServerApp] http://localhost:8888/lab?token=2fb9c878f5aceb8f14f943b68156a96dbbbe3ba6faeb5e5a
[I 2022-02-14 20:01:45.943 ServerApp]  or http://127.0.0.1:8888/lab?token=2fb9c878f5aceb8f14f943b68156a96dbbbe3ba6faeb5e5a
[I 2022-02-14 20:01:45.944 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2022-02-14 20:01:45.996 ServerApp]
To access the server, open this file in a browser:
    file:///C:/Users/bribr/AppData/Roaming/jupyter/runtime/jpserver-22988-open.html
Or copy and paste one of these URLs:
    http://localhost:8888/lab?token=2fb9c878f5aceb8f14f943b68156a96dbbbe3ba6faeb5e5a
 or http://127.0.0.1:8888/lab?token=2fb9c878f5aceb8f14f943b68156a96dbbbe3ba6faeb5e5a

[I 2022-02-14 20:01:50.067 LabApp] Build is up to date [I 2022-02-14 20:01:51.117 ServerApp] Kernel started: e231d584-3680-439f-8bf3-e6e4f53b59de [I 2022-02-14 20:01:51.122 ServerApp] Kernel started: f4b64169-44af-45e7-bcb3-7c6b12b3deef [E 2022-02-14 20:01:54.612 ServerApp] <LspStdIoReader(parent=<LanguageServerSession(language_server=pylsp, argv=['C:\Users\bribr\AppData\Local\Programs\Python\Python310\python.exe', '-m', 'pylsp'])>)> couldn't enqueue message: None (no colon in header line) Traceback (most recent call last): File "C:\Users\bribr\AppData\Roaming\Python\Python310\site-packages\tornado\httputil.py", line 179, in parse_line name, value = line.split(":", 1) ValueError: not enough values to unpack (expected 2, got 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\bribr\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_lsp\stdio.py", line 87, in read
    message = await self.read_one()
  File "C:\Users\bribr\AppData\Local\Programs\Python\Python310\lib\site-packages\jupyter_lsp\stdio.py", line 156, in read_one
    headers.parse_line(line)
  File "C:\Users\bribr\AppData\Roaming\Python\Python310\site-packages\tornado\httputil.py", line 181, in parse_line
    raise HTTPInputError("no colon in header line")
tornado.httputil.HTTPInputError: no colon in header line
Browser Output (recommended for all interface issues)
DevTools failed to load source map: Could not load content for http://localhost:8888/static/lab/jlab_core.0adf13f7678b3af0da97.js.map?v=0adf13f7678b3af0da97: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

321.517836e7e3596162…836e7e35961620fd1:1 LSP.WidgetAdapter: Could not retrieve current context Proxy [[Handler]]: Object get: ƒ (e,t,n) length: 3 name: "get" prototype: constructor: ƒ (e,t,n) [[Prototype]]: Object arguments: (...) caller: (...) [[FunctionLocation]]: 321.517836e7e3596162…836e7e35961620fd1:1 [[Prototype]]: ƒ () [[Scopes]]: Scopes[2] [[Prototype]]: Object constructor: ƒ Object() hasOwnProperty: ƒ hasOwnProperty() isPrototypeOf: ƒ isPrototypeOf() propertyIsEnumerable: ƒ propertyIsEnumerable() toLocaleString: ƒ toLocaleString() toString: ƒ toString() valueOf: ƒ valueOf() defineGetter: ƒ defineGetter() defineSetter: ƒ defineSetter() lookupGetter: ƒ lookupGetter() length: 1 name: "lookupGetter" arguments: (...) caller: (...) [[Prototype]]: ƒ () [[Scopes]]: Scopes[0] lookupSetter: ƒ lookupSetter() proto: (...) get proto: ƒ proto() set proto: ƒ proto() [[Target]]: Gn adapter: de {extension: ni, widget: fe, isDisposed: false, app: W, connection_manager: F, …} block_added_handlers: (18) [ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ] block_removed_handlers: [] ce_editor_to_cm_editor: Map(1) {ce => Ea} change: e {sender: Gn} cm_editor_to_ce_editor: Map(1) {Ea => ce} console: B {breadcrumbs: Array(2), _scope: 'LSP.WidgetAdapter:', singleton: K, debug: ƒ, log: ƒ, …} editor_name: "CodeMirrorEditor" editor_to_source_line: Map(1) {ce => 0} editor_to_source_line_new: Map(1) {ce => 0} isDisposed: false virtual_document: X {isDisposed: false, blank_lines_between_cells: 2, options: {…}, path: 'Test.ipynb', console: B, …} _event_wrappers: Map(9) {Array(2) => ƒ, Array(2) => ƒ, Array(2) => ƒ, Array(2) => ƒ, Array(2) => ƒ, …} _proxy: Proxy {editor_name: 'CodeMirrorEditor', isDisposed: false, _event_wrappers: Map(9), adapter: de, virtual_document: X, …} any_editor: (...) [[Prototype]]: Object [[IsRevoked]]: false 321.517836e7e35961620fd1.js?v=517836e7e35961620fd1:1 LSP.WidgetAdapter: Could not retrieve current context

brianhmj avatar Feb 15 '22 01:02 brianhmj

This is likely a bug in pylsp / some other package writing out to standard output. We should add a try-catch to be able to better debug these issues. In the meantime, would you feel comfortable with editing the stdio.py file to wrap headers.parse_line(line) into a try-except clause and in when the exception is caught see what the offending line is?

krassowski avatar Feb 15 '22 14:02 krassowski

Hi, I added a try-catch to debug. Below is the code in stdio.py file in jupyter_lsp, line 155.

            while line and line.strip():
                try:
                    headers.parse_line(line)
                except Exception as e:
                    print(e)

the Exception printed in console is "no colon in header line".

I looked up this specific exception and it seemed like it could possibly be a problem with using chrome, but I tested with Microsoft Edge and it throws the same exception.

References: https://github.com/jupyter/notebook/issues/2265

brianhmj avatar Feb 15 '22 19:02 brianhmj

Could you please try again, but instead of print(e) use print(line)?

It is not related to any specific browser, this is a problem on the backend.

krassowski avatar Feb 15 '22 19:02 krassowski

Yes of course. Thank you for the help. The printed line is pyls_lint.

I also added a print(line) before the try-catch and it seems like the normal input for line should be if the form of Content-Length: 49. Not sure what is causing this issue.

brianhmj avatar Feb 15 '22 19:02 brianhmj

It's pyls-memestra. It used to have a line printing: print("pyls_lint 🐔"), now commented out which was fixed three months ago by https://github.com/QuantStack/pyls-memestra/pull/51. I commented https://github.com/QuantStack/pyls-memestra/pull/51#issuecomment-1003365375 at the time that this line indeed should not be there as it will cause this error. It looks like there was no release since. You could

  • a) ask the maintainers of https://github.com/QuantStack/pyls-memestra to tag a new release with a bugfix.
  • b) uninstall this plugin in the meantime

krassowski avatar Feb 15 '22 20:02 krassowski

I changed the title and labelled it as an enhancement, as we could do a better job at surfacing the faulty line when something goes wrong. Thank you for reporting this issue.

krassowski avatar Feb 15 '22 20:02 krassowski

Thank you so much! I had downloaded the source code and it was commented out but looks like when you pip install the package, it is not commented out. I will ping the maintainers to fix the code, and disable the package for now. Looking forward to improved exception handling!

brianhmj avatar Feb 15 '22 20:02 brianhmj

Thanks for the confirmation. I will reopen this issue to keep track of the improvement.

krassowski avatar Feb 15 '22 21:02 krassowski