{"record":{"id":"240422c1e485f433","repo":"linera-io/linera-protocol","slug":"query-result-subscription-failed-errors","errorCode":null,"errorMessage":"Query result subscription failed: {errors:?}","messagePattern":"Query result subscription failed: (.+?)","errorType":"exception","errorClass":"anyhow","httpStatus":null,"severity":"error","filePath":"linera-service/src/cli_wrappers/wallet.rs","lineNumber":2133,"sourceCode":"            text == \"{\\\"type\\\":\\\"connection_ack\\\"}\",\n            \"Unexpected response: {text}\"\n        );\n        let query_json = json!({\n          \"id\": \"1\",\n          \"type\": \"start\",\n          \"payload\": {\n            \"query\": query,\n            \"variables\": {},\n            \"operationName\": null\n          }\n        });\n        websocket.send(query_json.to_string().into()).await?;\n        Ok(Box::pin(websocket.map_err(anyhow::Error::from).and_then(\n            |message| async {\n                let text = message.into_text()?;\n                let value: Value = serde_json::from_str(&text).context(\"invalid JSON\")?;\n                if let Some(errors) = value[\"payload\"].get(\"errors\") {\n                    bail!(\"Query result subscription failed: {errors:?}\");\n                }\n                Ok(value[\"payload\"][\"data\"][\"queryResult\"].clone())\n            },\n        )))\n    }\n}\n\n/// A running faucet service.\npub struct FaucetService {\n    port: u16,\n    child: Child,\n    _temp_dir: tempfile::TempDir,\n    terminated: bool,\n}\n\nimpl Drop for FaucetService {\n    fn drop(&mut self) {\n        if !self.terminated {","sourceCodeStart":2115,"sourceCodeEnd":2151,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-service/src/cli_wrappers/wallet.rs#L2115-L2151","documentation":"Raised by the NodeExt test wrapper (cli_wrappers/wallet.rs) when the GraphQL websocket subscription `subscription { queryResult(name:..., chainId:..., applicationId:...) }` against `ws://localhost:{port}/ws` returns an `errors` array in a payload message. The node accepted the websocket connection but failed the queryResult subscription server-side. It is delivered asynchronously as an `Err` item on the returned stream of JSON values.","triggerScenarios":"Calling `node.query_result(name, chain_id, application_id)` where the application ID is wrong or the application is not registered/running on that chain; the `name` does not match a query exposed by the application's GraphQL module; the chain is not tracked by the node; client/node version skew changes the queryResult schema or argument formatting.","commonSituations":"Integration tests that subscribe to an application's query results before publishing/registering the application; formatting mismatches of `ApplicationId`/`ChainId` (`e5:...:...:0` style strings) after an SDK upgrade; querying an application on a chain owned by a different shard/validator.","solutions":["Confirm the application is registered on that chain (check via a one-shot GraphQL query for the chain's applications) and fix the application ID","Verify the query `name` matches a query in the application's generated GraphQL schema","Rebuild harness and node binaries from the same commit to eliminate schema/formatting differences","Re-create the subscription — the stream dies once the node has sent the error payload"],"exampleFix":"// before\nlet query = format!(\n    r#\"subscription {{ queryResult(name: \"{name}\", chainId: \"{chain_id}\", applicationId: \"{application_id}\") }}\"#\n);\n\n// after — always inspect each stream item for the server-side error\nlet mut stream = node.query_result(name, chain_id, application_id).await?;\nwhile let Some(item) = stream.next().await {\n    let value = item.context(\"queryResult stream ended with error\")?;\n}","handlingStrategy":"try-catch","validationCode":"// Rust: confirm the application is registered on the chain before subscribing\nlet response = node\n    .query_node(&format!(\n        \"query {{ applications(chainId: \\\"{chain_id}\\\") {{ applicationId }} }}\"\n    ))\n    .await?;\nlet registered = response[\"data\"][\"applications\"]\n    .as_array()\n    .map(|apps| apps.iter().any(|a| a[\"applicationId\"] == application_id.to_string()))\n    .unwrap_or(false);\nanyhow::ensure!(registered, \"application {application_id} not registered on {chain_id}\");","typeGuard":null,"tryCatchPattern":"let mut stream = node.query_result(name, chain_id, application_id).await?;\nwhile let Some(item) = stream.next().await {\n    let value = match item {\n        Ok(v) => v,\n        Err(e) if e.to_string().contains(\"Query result subscription failed\") => {\n            // wrong applicationId / query name / untracked chain: fix inputs before retrying\n            return Err(e.context(\"queryResult subscription rejected by node\"));\n        }\n        Err(e) => return Err(e),\n    };\n    // handle value\n}","preventionTips":["Verify the application ID and query name against the application's generated GraphQL schema before subscribing","Treat every stream item as fallible — the error arrives mid-stream","Register and publish the application (and wait for the block) before subscribing to its queries","Pin harness and node binaries to the same linera revision"],"tags":["graphql","websocket","subscription","application","testing"],"backgroundTag":"graphql-subscription-errors","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}