sublimelsp / LSP-pyright

Python support for Sublime's LSP plugin provided through microsoft/pyright.
MIT License
126 stars 13 forks source link

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

Open artofhuman opened 7 months ago

artofhuman commented 7 months ago

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)
rchl commented 7 months ago

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

artofhuman commented 7 months ago
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.

jfcherng commented 7 months ago

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

artofhuman commented 7 months ago

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

jfcherng commented 7 months ago

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

artofhuman commented 7 months ago

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

rchl commented 7 months ago

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.

jfcherng commented 7 months ago

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

rchl commented 7 months ago

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.

rwols commented 7 months ago

@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