Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff Crashes with ValueError #132

Closed
rajeee opened this issue Feb 17, 2023 · 12 comments
Closed

Ruff Crashes with ValueError #132

rajeee opened this issue Feb 17, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@rajeee
Copy link

rajeee commented Feb 17, 2023

Ruff shows this output in VS Code.

Using bundled executable: c:\Users\rajen\.vscode\extensions\charliermarsh.ruff-2023.6.0-win32-x64\bundled\libs\bin\ruff.exe
Running Ruff with: ['c:\\Users\\rajen\\.vscode\\extensions\\charliermarsh.ruff-2023.6.0-win32-x64\\bundled\\libs\\bin\\ruff.exe', '--no-cache', '--no-fix', '--quiet', '--format', 'json', '-', 'line-length=120', '--stdin-filename', 'c:\\Users\\rajen\\PycharmProjects\\Python Playground\\empty.py']
Failed to handle user defined notification "textDocument/didOpen": (DidOpenTextDocumentParams(text_document=TextDocumentItem(uri='file:///c%3A/Users/rajen/PycharmProjects/Python%20Playground/empty.py', language_id='python', version=1, text='')),)
Traceback (most recent call last):
  File "c:\Users\rajen\.vscode\extensions\charliermarsh.ruff-2023.6.0-win32-x64\bundled\libs\pygls\protocol.py", line 84, in decorator
    self._execute_notification(user_func, *args, **kwargs)
  File "c:\Users\rajen\.vscode\extensions\charliermarsh.ruff-2023.6.0-win32-x64\bundled\libs\pygls\protocol.py", line 228, in _execute_notification
    handler(*params)
  File "c:\Users\rajen\.vscode\extensions\charliermarsh.ruff-2023.6.0-win32-x64\bundled\libs\ruff_lsp\server.py", line 85, in did_open
    diagnostics: list[Diagnostic] = _linting_helper(document)
  File "c:\Users\rajen\.vscode\extensions\charliermarsh.ruff-2023.6.0-win32-x64\bundled\libs\ruff_lsp\server.py", line 117, in _linting_helper
    return _parse_output_using_regex(result.stdout) if result.stdout else []
  File "c:\Users\rajen\.vscode\extensions\charliermarsh.ruff-2023.6.0-win32-x64\bundled\libs\ruff_lsp\server.py", line 155, in _parse_output_using_regex
    start = Position(
  File "<attrs generated init lsprotocol.types.Position>", line 7, in __init__
    __attr_validator_character(self, __attr_character, self.character)
  File "c:\Users\rajen\.vscode\extensions\charliermarsh.ruff-2023.6.0-win32-x64\bundled\libs\lsprotocol\validators.py", line 45, in uinteger_validator
    raise ValueError(
ValueError: Position.character should be in range [0:2147483647], but was -1.
@charliermarsh charliermarsh added the bug Something isn't working label Feb 17, 2023
@charliermarsh
Copy link
Member

Thanks for the trace!

@charliermarsh
Copy link
Member

This is probably a bug in Ruff. Will look into it.

@charliermarsh
Copy link
Member

Are you able to share the file contents?

@rajeee
Copy link
Author

rajeee commented Feb 17, 2023

It seems to be an issue with VS Code integration. I updated the traceback to include all of the info. The file empty.py is literally empty.

@lasinludwig
Copy link

I think I have pretty much the same problem. When I have Ruff activated and try to save any file, all the code in that file gets deleted and I get this error:

Unexpected error in LSP server, see server's logs for details

I also described it in issue #58 , but that issue derailed a bit and was closed.

@charliermarsh
Copy link
Member

I fixed one thing in Ruff that could be the cause of this. It would've gone out in 0.0.248.

@lasinludwig
Copy link

I just tried out the pre-release version and the LSP server doesn't crash anymore. 👍

However now I'm getting the following errors on every file:

  • The system cannot find the file specified. (os error 2) Ruff(E902) [Ln 1, Col 1]
  • The filename, directory name, or volume label syntax is incorrect. (os error 123) Ruff(E902) [Ln 1, Col 1]

Also I still have the problem that when I try to save a file, all the code in it gets deleted.

...is this a separate issue?

@charliermarsh
Copy link
Member

Yeah I figured this was what was happening -- that there was some kind of IO error, and Ruff was returning a bad value for that error, which was causing the server to crash. Now, at least, we can see the error without the LSP crashing.

@charliermarsh
Copy link
Member

(So we can keep this open.)

@lasinludwig
Copy link

Just tried it again after a while and it doesn't crash anymore! 😃

There's still the problem, that it deletes the entire contents of the file when I save, but I was able to get around that by disabling the "organize imports" option. 👍

@tuhinsharma121
Copy link

tuhinsharma121 commented Apr 14, 2024

I am encountering the same error for ruff==0.3.7 python --version is 3.11

ruff fix

warning: `ruff <path>` is deprecated. Use `ruff check <path>` instead.  
fix:1:1: E902 No such file or directory (os error 2)  
Found 1 error.

Is there any fix?

@trag1c
Copy link

trag1c commented Apr 14, 2024

I am encountering the same error for ruff==0.3.7 python --version is 3.11

ruff fix

warning: `ruff <path>` is deprecated. Use `ruff check <path>` instead.  
fix:1:1: E902 No such file or directory (os error 2)  
Found 1 error.

Is there any fix?

What you likely want is ruff check <path> --fix; as you can see in the output ruff fix gets interpreted as "check the file called fix"

Also I don't see how this is related to the original issue?

howroyd added a commit to howroyd/docs that referenced this issue Jul 12, 2024
`ruff <path>` has been removed. Use `ruff check <path>` instead.

astral-sh/ruff-vscode#132
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants