linera-io/linera-protocol · error
expected whitespace after 'query' keyword
Error message
expected whitespace after 'query' keyword
What it means
parse_allowed_subscription in linera-service parses each --allow-subscription CLI value into a RegisteredQuery. It requires the trimmed string to start with the literal keyword 'query' followed by at least one whitespace character, so the keyword can be told apart from the operation name that follows. This error means the input did begin with 'query' but the next character was not whitespace, e.g. 'query{' or 'queryName'.
Source
Thrown at linera-service/src/query_subscription.rs:35
use tracing::{debug, warn};
/// A named GraphQL query string registered at startup via `--allow-subscription`.
#[derive(Clone, Debug)]
pub struct RegisteredQuery {
/// The operation name used to refer to the query.
pub name: String,
/// The full GraphQL query string.
pub query: String,
}
/// Parses a GraphQL query string like `query Name { ... }` and extracts the operation name.
pub fn parse_allowed_subscription(s: &str) -> anyhow::Result<RegisteredQuery> {
let trimmed = s.trim();
let rest = trimmed
.strip_prefix("query")
.ok_or_else(|| anyhow::anyhow!("expected query to start with 'query', got: {s}"))?;
// The character right after "query" must be whitespace (not part of a longer word).
anyhow::ensure!(
rest.starts_with(char::is_whitespace),
"expected whitespace after 'query' keyword"
);
let rest = rest.trim_start();
// Extract the operation name: sequence of alphanumeric/underscore chars.
let name = rest
.split(|c: char| !c.is_alphanumeric() && c != '_')
.next()
.unwrap_or_default();
anyhow::ensure!(
!name.is_empty(),
"expected an operation name after 'query', e.g. 'query MyQuery {{ ... }}'"
);
Ok(RegisteredQuery {
name: name.to_string(),
query: trimmed.to_string(),
})
}View on GitHub (pinned to 6c226ddcb3)
Solutions
- Put whitespace between the keyword and the rest: use 'query MyQuery { ... }'
- If you wrote an anonymous operation like 'query { ... }', add an operation name — this parser requires one (see the sibling error for missing names)
- Quote the whole argument in the shell so whitespace survives: --allow-subscription 'query MyQuery { field }'
- Check for invisible characters (e.g. a BOM or non-breaking space) pasted from docs or chat, which do count as whitespace but may surprise you; use a plain ASCII space
Example fix
# before
--allow-subscription 'query{ transfers { id } }'
# after
--allow-subscription 'query Transfers { transfers { id } }' Defensive patterns
Strategy: validation
Validate before calling
// Rust: reject bad --allow-subscription values before startup
fn starts_with_query_keyword(s: &str) -> bool {
let t = s.trim();
match t.strip_prefix("query") {
Some(rest) => rest.starts_with(char::is_whitespace),
None => false,
}
}
for sub in &allowed_subscriptions {
if !starts_with_query_keyword(sub) {
return Err(config_error(format!("bad --allow-subscription: {sub}")));
}
} Type guard
fn is_wellformed_subscription(s: &str) -> bool {
let t = s.trim();
t.strip_prefix("query").is_some_and(|r| r.starts_with(char::is_whitespace))
} Try / catch
match parse_allowed_subscription(&arg) {
Ok(registered) => registry.push(registered),
Err(e) => {
eprintln!("invalid --allow-subscription value {arg:?}: {e:#}");
std::process::exit(2);
}
} Prevention
- Always quote the whole GraphQL string in shell commands so whitespace survives
- Add a startup config lint that runs starts_with_query_keyword over all subscription flags before the node boots
- Prefer named operations everywhere: 'query Name { ... }' satisfies both this check and the name check
When it happens
Trigger: Starting the linera-service node with a --allow-subscription value such as 'query{ transfers { id } }' (no space before the brace) or 'queryTransfers { ... }' (name glued to the keyword). The parse runs at startup from run(), so the process fails before any chain or network activity.
Common situations: Shell quoting that collapses or drops whitespace; copy-pasting a minified GraphQL query; writing an anonymous operation without a space; muscle memory from other GraphQL clients that accept 'query{...}'.
Related errors
- expected an operation name after 'query', e.g. 'query MyQuer
- expected query to start with 'query', got: {s}
- no subscription query registered with name '{}'
- The input has not matched: {input}
- Invalid application ID
AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22).
Data as JSON: /api/errors/dd2000f58db6d3a1.
Report an issue: GitHub.