linera-io/linera-protocol · error · anyhow
Query "{}" failed: {}
Error message
Query "{}" failed: {} What it means
Raised by `NodeExt::query_node` in the linera-service test wrappers when a plain GraphQL query POSTed to the node's HTTP endpoint returns a 200 response whose body contains an `errors` array. The node's GraphQL layer rejected the query itself (syntax, validation, or execution error). The message includes the truncated query and the server's error list, so the exact cause is embedded in the error text.
Source
Thrown at linera-service/src/cli_wrappers/wallet.rs:2234
}
Err(error) => {
let query = truncate_query_output_serialize(&query);
return Err(error)
.with_context(|| format!("run_json_query: failed to post query={query}"));
}
};
ensure!(
response.status().is_success(),
"Query \"{}\" failed: {}",
truncate_query_output_serialize(&query),
response
.text()
.await
.unwrap_or_else(|error| format!("Could not get response text: {error}"))
);
let value: Value = response.json().await.context("invalid JSON")?;
if let Some(errors) = value.get("errors") {
bail!(
"Query \"{}\" failed: {}",
truncate_query_output_serialize(&query),
errors
);
}
return Ok(value);
}
unreachable!()
}
/// Runs the given string as a GraphQL query, wrapping it in `query { ... }`.
pub async fn query(&self, query: impl AsRef<str>) -> Result<Value> {
let query = query.as_ref();
self.run_graphql_query(&format!("query {{ {query} }}"))
.await
}
/// Runs the given GraphQL query and deserializes the named field of the response.View on GitHub (pinned to 6c226ddcb3)
Solutions
- Read the embedded `errors` array in the message — it names the exact GraphQL validation failure
- Paste the printed query into the node's GraphQL playground (http://localhost:{port}) and fix the reported field/argument issues
- Check quoting of `format!`-interpolated IDs (raw strings `r#"..."#` plus escaped quotes)
- Align client and node versions — rebuild both from the same commit
Example fix
// before
let query = format!("query {{ block(chainId: \"{}\") {{ hash }} }}", chain_id);
// after
let query = format!(r#"query {{ block(chainId: "{chain_id}") {{ hash }} }}"#); Defensive patterns
Strategy: try-catch
Validate before calling
// Rust: smoke-test a dynamically built query against the schema before query_node
// (cheap: run it once; if the schema rejects it, you get the error synchronously)
#[cfg(test)]
fn assert_query_is_single_operation(query: &str) -> anyhow::Result<()> {
let trimmed = query.trim();
anyhow::ensure!(
trimmed.starts_with("query") || trimmed.starts_with("subscription") || trimmed.starts_with('{'),
"query does not look like a GraphQL operation: {trimmed}"
);
Ok(())
} Try / catch
match node.query_node(&query).await {
Ok(value) => { /* use value */ }
Err(e) if e.to_string().contains("Query \"") => {
// GraphQL-level failure: the message contains the truncated query + server errors.
// Log and surface it; retrying unchanged will fail again.
return Err(e);
}
Err(e) => return Err(e),
} Prevention
- Build queries with raw-string format! (r#"..."#) so interpolated IDs keep their quotes intact
- Test new queries once in the node's GraphQL playground before embedding them in tests
- Read the embedded errors array in the message — it pinpoints the failing field or argument
- Regenerate fixtures after SDK upgrades that rename GraphQL fields
When it happens
Trigger: Calling `query_node` with a malformed GraphQL string (unbalanced braces, bad quoting from `format!`), unknown fields or arguments, wrong argument types, or IDs (chainId/applicationId/blockHash) that do not exist on that node.
Common situations: Hand-built query strings where interpolated IDs break string quoting; schema changes between the client wrapper and the node binary (fields renamed/removed); querying a chain or application that was never created on this node; tests running against a stale node fixture.
Related errors
- Notification subscription failed: {errors:?}
- Query {argument:?} is invalid and could not be deserialized
- Query result subscription failed: {errors:?}
- Expected an `ExecutionError`. Got: {self:#?}
- Expected an `ExecutionError`. Got: {chain_error:#?}
AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22).
Data as JSON: /api/errors/1221144b4ac681ee.
Report an issue: GitHub.