Skip to content

fix: Discover protocol should only parse stdout - #22903

Merged
ShoyuVanilla merged 2 commits into
rust-lang:masterfrom
Wilfred:stderr_discovery
Jul 27, 2026
Merged

fix: Discover protocol should only parse stdout#22903
ShoyuVanilla merged 2 commits into
rust-lang:masterfrom
Wilfred:stderr_discovery

Conversation

@Wilfred

@Wilfred Wilfred commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Currently r-a expects JSON on both stdout and stderr from the discover command. This means that the discover command can't log any warnings, and any accidental stderr logs breaks discovery entirely.

Instead, only parse stdout, and update JsonLinesParser to require implementors to be explicit.

Currently JsonLinesParser::from_line is called for both stdout and
stderr, so trait implementers cannot distinguish stdout and stderr.

Define a separate JsonLinesParser::from_stderr_line to make the
stdout/stderr distinction explicit, and update use sites. This is not
a behaviour change.

AI disclosure: Partially written by Codex and GPT-5.5.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 24, 2026
@Wilfred

Wilfred commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

cc @davidbarsky I'm pretty sure the old behaviour was entirely accidental due to the old trait API, but let me know what you think.

Comment thread crates/rust-analyzer/src/discover.rs Outdated
}

fn from_stderr_line(&self, line: &str, _error: &mut String) -> Option<DiscoverProjectMessage> {
tracing::warn!(%line, "discover command stderr");

@ChayimFriedman2 ChayimFriedman2 Jul 24, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on the edge about this. Is every stderr line really a warning? I see three options:

  1. Do nothing, leave it as warn!(). I don't like this.
  2. Downgrade to info!() or even debug!().
  3. Expect JSON with only the level and the message.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stderr output is definitely rare, or we'd have hit this issue sooner! :)

I picked warn! because I thought it was nice to see the stderr output by default. That said, info! also seems fine: it solves my issue with unexpected logging from the rust-project binary breaking people's rust-analyzer setup.

Switched to info! and amended the commit.

@Wilfred
Wilfred force-pushed the stderr_discovery branch from ed5af79 to ae9fa8c Compare July 24, 2026 15:44
@davidbarsky

Copy link
Copy Markdown
Contributor

cc @davidbarsky I'm pretty sure the old behaviour was entirely accidental due to the old trait API, but let me know what you think.

I think the intention was have all errors go over JSON, but unlike Chayim, I don't think I have concerns about using stderr for error collection.

(side note: I got some rust-project changes, if you got a moment: facebook/buck2#1398)

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

You need to UPDATE_EXPECT=1 cargo test.

Previously we read both stdout and stderr in the discover
protocol. Depending on the tool generating rust-project JSON, this
meant that a single stderr log message could break discovery.

Instead, only look for JSON from the discover command's stdout, and
forward stderr to the rust-analyzer logs.

Update both the implementation and the discover protocol docs to
reflect this behaviour.

AI disclosure: Code partly written by GPT-5.5.
@Wilfred
Wilfred force-pushed the stderr_discovery branch from ae9fa8c to 3bbccf6 Compare July 27, 2026 10:03
@Wilfred

Wilfred commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Oops, fixed.

@ShoyuVanilla
ShoyuVanilla added this pull request to the merge queue Jul 27, 2026
Merged via the queue into rust-lang:master with commit 0402740 Jul 27, 2026
19 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants