LSP-pyright icon indicating copy to clipboard operation
LSP-pyright copied to clipboard

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2

Open artofhuman opened this issue 1 year ago • 10 comments

Hi. I have the error after start LSP.

LSP-pyright: INFO: poetry.lock detected. Run subprocess command: poetry env info -p
Unable to start subprocess for LSP-pyright
Traceback (most recent call last):
  File "/Users/semyonpupkov/Library/Application Support/Sublime Text/Installed Packages/LSP.sublime-package/plugin/core/windows.py", line 265, in start_async
    cwd = plugin_class.on_pre_start(self._window, initiating_view, workspace_folders, config)
  File "/Users/semyonpupkov/Library/Application Support/Sublime Text/Installed Packages/LSP-pyright.sublime-package/plugin.py", line 75, in on_pre_start
    python_path = cls.python_path(configuration.settings, workspace_folders)
  File "/Users/semyonpupkov/Library/Application Support/Sublime Text/Installed Packages/LSP-pyright.sublime-package/plugin.py", line 199, in python_path
    python_path = cls.python_path_from_venv(workspace_folder)
  File "/Users/semyonpupkov/Library/Application Support/Sublime Text/Installed Packages/LSP-pyright.sublime-package/plugin.py", line 247, in python_path_from_venv
    universal_newlines=True,
  File "./python3.3/subprocess.py", line 578, in check_output
  File "./python3.3/subprocess.py", line 907, in communicate
  File "./python3.3/subprocess.py", line 479, in _eintr_retry_call
  File "./python3.3/encodings/ascii.py", line 26, in decode
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 547: ordinal not in range(128)

artofhuman avatar Jan 31 '24 07:01 artofhuman

What output are you getting when running poetry env info -p in the terminal, in that workspace?

rchl avatar Jan 31 '24 08:01 rchl

poetry env info -p        
Warning: Found deprecated key 'default' or 'secondary' in pyproject.toml configuration for source kontur. Please provide the key 'priority' instead. Accepted values are: 'default', 'primary', 'secondary', 'supplemental', 'explicit'.
Warning: Found deprecated priority 'secondary' for source 'kontur' in pyproject.toml. Consider changing the priority to one of the non-deprecated values: 'default', 'primary', 'supplemental', 'explicit'.
/Users/semyonpupkov/Library/Caches/pypoetry/virtualenvs/reco-py-gv35q0vK-py3.11

I've fixed the warning, but ther error still appears.

artofhuman avatar Jan 31 '24 08:01 artofhuman

That output looks good to me. All in ASCII. 🤔

jfcherng avatar Jan 31 '24 08:01 jfcherng

I added explicit path to python and that fixed this error. (because autodetection doesn't run :))

artofhuman avatar Jan 31 '24 08:01 artofhuman

That doesn't sound like something we can improve? But weirdly it worked when executed in terminal.

jfcherng avatar Jan 31 '24 08:01 jfcherng

If package can't detect python path, maybe better to use default python, or handle exception and suggest how to setup path explicitly

artofhuman avatar Jan 31 '24 08:01 artofhuman

The package just runs poetry env info -p in a subprocess. It doesn't use any python specifically and relies on shell PATH being set correctly.

I guess in your case it just can't find poetry and the error that your shell gives in this case has some weird characters.

That said, it might still be possible to handle this error case better.

rchl avatar Jan 31 '24 09:01 rchl

I guess in your case it just can't find poetry and the error that your shell gives in this case has some weird characters.

I think that would be caught by https://github.com/sublimelsp/LSP-pyright/blob/4e7b80edd8034e5750119fbc943921d25df65287/plugin.py#L250-L251

jfcherng avatar Jan 31 '24 09:01 jfcherng

No, when you start subprocess with shell=True (which is the case here) it can't know what the error is in such details since it's all handled by the shell.

rchl avatar Jan 31 '24 09:01 rchl

@artofhuman you seem to be using macOS. Sublime uses a specific file of your default shell to determine the right $PATH for that OS. See: https://lsp.sublimetext.io/troubleshooting/#updating-the-path-used-by-lsp-servers

rwols avatar Jan 31 '24 13:01 rwols