From 7f267f87f34baf0daa8152f297f3cbe394055e49 Mon Sep 17 00:00:00 2001 From: John Hughes Date: Sat, 13 Jan 2024 14:11:05 +0100 Subject: [PATCH] Provide a better error message when trying to generate rust-project.json (#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. --- tools/rust_analyzer/aquery.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/rust_analyzer/aquery.rs b/tools/rust_analyzer/aquery.rs index 2bf2eef0cd..3697b0e47f 100644 --- a/tools/rust_analyzer/aquery.rs +++ b/tools/rust_analyzer/aquery.rs @@ -110,7 +110,18 @@ fn parse_aquery_output_files( execution_root: &Path, aquery_stdout: &str, ) -> anyhow::Result> { - 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::(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