Skip to content

ruff analyze graph | head -n 10 panics #13442

Description

@tpgillam

It seems like ruff analyze graph is sometimes unhappy when its output isn't fully consumed.

Tested with ruffs 0.6.6 and 0.6.7:

> uv run ruff analyze graph -q | wc -l
2382
> uv run ruff analyze graph -q | head -n 10

<snip 10 correct lines of output>

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 library/std/src/io/stdio.rs:1118:9:
failed printing to stdout: Broken pipe (os error 32)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

A full example to reproduce, starting in an otherwise empty directory, would be:

git clone https://github.com/Eomys/pyleecan.git --depth=1
uv init
uv add ruff==0.6.7
uv run ruff analyze graph | head -n 10

edit: above is running on MacOS 14.6.1 . Although head is the GNU version from homebrew's coreutils

Activity

  1. MichaReiser commented on Sep 21, 2024

    @MichaReiser
    Member

    That's probably due to a println usage. We should use writeln instead and propagate the error when the pipe breaks

  2. added
    bugAn issue describing something that isn't working, or a PR that fixes a bug
    on Sep 21, 2024
  3. pixelb commented on Sep 22, 2024

    @pixelb

    Just a suggestion to not propagate pipe "errors", as this is not really an error in the normal sense
    https://www.pixelbeat.org/programming/sigpipe_handling.html

  4. charliermarsh commented on Sep 23, 2024

    @charliermarsh
    Member

    I got it.

  5. BurntSushi commented on Sep 23, 2024

    @BurntSushi
    Member

    This is how ripgrep handles pipe errors: https://github.com/BurntSushi/ripgrep/blob/bf63fe8f258afc09bae6caa48f0ae35eaf115005/crates/core/main.rs#L55-L61

    There are other approaches, but this is my favorite because:

    • It doesn't require any platform specific APIs.
    • It doesn't require inspecting or dealing with errors specially every time writeln! is called. You just propagate it like normal and only treat it differently at the top-level of the program in one place.
    • It matches the expected behavior: a pipe error should make the program stop working and exit gracefully.

    But yes, basically any println! automatically introduces a potential bug of this variety.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugAn issue describing something that isn't working, or a PR that fixes a bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions