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

[Panic] check file from stdin #8027

Closed
JMarkin opened this issue Oct 17, 2023 · 1 comment · Fixed by #8029
Closed

[Panic] check file from stdin #8027

JMarkin opened this issue Oct 17, 2023 · 1 comment · Fixed by #8029
Assignees
Labels
bug Something isn't working

Comments

@JMarkin
Copy link

JMarkin commented Oct 17, 2023

Hello, If I try check file from stdin ruff crashed, but it printed errors.

error: Ruff crashed. If you could open an issue at:

    https://github.com/astral-sh/ruff/issues/new?title=%5BPanic%5D

...quoting the executed command, along with the relevant file contents and `pyproject.toml` settings, we'd be very appreciative!

thread 'main' panicked at 'assertion failed: total > 0', crates/ruff_cli/src/printer.rs:470:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
-:1:19: F401 [*] `.vars.TokenVar` imported but unused
-:1:29: F401 [*] `.vars.UserVar` imported but unused

example file

from .vars import TokenVar, UserVar

example config

[tool.ruff]
line-length = 120
show-fixes = true
select = [
  # default
  "F",
  "E",
  # flake8-bugbear
  "B",
  # flake8-quotes
  "Q",
  # isort
  "I",
  # flake8-comprehensions
  "C",
]
ignore = ["B008"]

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]

[tool.ruff.pydocstyle]
convention = "google"

[tool.ruff.flake8-comprehensions]
allow-dict-calls-with-keyword-arguments = true

command: cat src/__init__.py | ruff check -

@charliermarsh
Copy link
Member

Thanks -- it looks like a bug related to show-fixes = true.

@charliermarsh charliermarsh added the bug Something isn't working label Oct 17, 2023
@charliermarsh charliermarsh self-assigned this Oct 17, 2023
charliermarsh added a commit that referenced this issue Oct 18, 2023
## Summary

When linting, we store a map from file path to fixes, which we then use
to show a fix summary in the printer.

In the printer, we assume that if the map is non-empty, then we have at
least one fix. But this isn't enforced by the fix struct, since you can
have an entry from (file path) to (empty fix table). In practice, this
only bites us when linting from `stdin`, since when linting across
multiple files, we have an `AddAssign` on `Diagnostics` that avoids
adding empty entries to the map. When linting from `stdin`, we create
the map directly, and so it _is_ possible to have a non-empty map that
doesn't contain any fixes, leading to a panic.

This PR introduces a dedicated struct to make these constraints part of
the formal interface.

Closes #8027.

## Test Plan

`cargo test` (notice two failures are removed)
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

Successfully merging a pull request may close this issue.

2 participants