Skip to content

Commit

Permalink
Provide a better error message when trying to generate rust-project.j…
Browse files Browse the repository at this point in the history
…son (bazelbuild#2196)

Currently when trying to generate a `rust-project.json`, if there aren't
actually any Rust targets defined, the script mysteriously fails.

This adds a better error message.
  • Loading branch information
jondo2010 authored and Vinh Tran committed Jan 17, 2024
1 parent 2e3d708 commit 7f267f8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tools/rust_analyzer/aquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,18 @@ fn parse_aquery_output_files(
execution_root: &Path,
aquery_stdout: &str,
) -> anyhow::Result<Vec<PathBuf>> {
let out: AqueryOutput = serde_json::from_str(aquery_stdout)?;
let out: AqueryOutput = serde_json::from_str(aquery_stdout).map_err(|_| {
// Parsing to `AqueryOutput` failed, try parsing into a `serde_json::Value`:
match serde_json::from_str::<serde_json::Value>(aquery_stdout) {
Ok(serde_json::Value::Object(_)) => {
// If the JSON is an object, it's likely that the aquery command failed.
anyhow::anyhow!("Aquery returned an empty result, are there any Rust targets in the specified paths?.")
}
_ => {
anyhow::anyhow!("Failed to parse aquery output as JSON")
}
}
})?;

let artifacts = out
.artifacts
Expand Down

0 comments on commit 7f267f8

Please sign in to comment.