{"record":{"id":"d4bb7a28107c3e7f","repo":"linera-io/linera-protocol","slug":"query-failed-after-retries","errorCode":null,"errorMessage":"Query \"{}\" failed after {} retries.","messagePattern":"Query \"(.+?)\" failed after (.+?) retries\\.","errorType":"exception","errorClass":"anyhow","httpStatus":null,"severity":"error","filePath":"linera-service/src/cli_wrappers/wallet.rs","lineNumber":1959,"sourceCode":"                \"Query \\\"{}\\\" failed: {}\",\n                truncate_query_output(query),\n                response\n                    .text()\n                    .await\n                    .unwrap_or_else(|error| format!(\"Could not get response text: {error}\"))\n            );\n            let value: Value = response.json().await.context(\"invalid JSON\")?;\n            if let Some(errors) = value.get(\"errors\") {\n                tracing::warn!(\n                    \"Query \\\"{}\\\" failed: {}\",\n                    truncate_query_output(query),\n                    errors\n                );\n            } else {\n                return Ok(value[\"data\"].clone());\n            }\n        }\n        bail!(\n            \"Query \\\"{}\\\" failed after {} retries.\",\n            truncate_query_output(query),\n            n_try\n        );\n    }\n\n    /// Creates an application from a published module via the `createApplication` mutation.\n    pub async fn create_application<\n        Abi: ContractAbi,\n        Parameters: Serialize,\n        InstantiationArgument: Serialize,\n    >(\n        &self,\n        chain_id: &ChainId,\n        module_id: &ModuleId<Abi, Parameters, InstantiationArgument>,\n        parameters: &Parameters,\n        argument: &InstantiationArgument,\n        required_application_ids: &[ApplicationId],","sourceCodeStart":1941,"sourceCodeEnd":1977,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-service/src/cli_wrappers/wallet.rs#L1941-L1977","documentation":"`query_node` POSTs a GraphQL query to the node service and inspects the JSON body: a top-level `errors` field makes it log the errors and retry; a transport timeout also retries; only a clean response with `data` returns. After `n_try` exhausted attempts it bails with the truncated query text and the attempt count. Each failed attempt logs a warn with the GraphQL errors, so the bail is the aggregate of a consistently failing query.","triggerScenarios":"Every attempt returns GraphQL errors — querying a chain the service does not track, unknown/misnamed fields, unauthorized subscriptions — or every attempt times out against an overloaded or dead service.","commonSituations":"Integration tests racing ahead of chain/application creation; node service still syncing after startup; schema changes between wrapper and service versions; service starved under load so reqwest times out repeatedly.","solutions":["Check the warn logs — each attempt logs the exact GraphQL errors the service returned","Verify the query itself: chain ID format, field names, and that the service tracks the chain","Ensure the node service has started and finished critical syncing before issuing queries","Retry after the service recovers, or call query_node with a higher retry count if the API allows it"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Only issue queries the service can answer: chain must be tracked.\nif !client.query_applications_list().await?.iter().any(/* ... */) {\n    // wait for service readiness instead of burning all retries\n    tokio::time::sleep(Duration::from_secs(1)).await;\n}","typeGuard":null,"tryCatchPattern":"match client.query_node(query).await {\n    Err(e) if e.to_string().contains(\"failed after\") => {\n        // retries already exhausted: the query itself is likely wrong,\n        // check the per-attempt GraphQL errors in the warn logs before retrying\n        log::error!(\"query permanently failed: {e}\");\n        return Err(e);\n    }\n    result => result,\n}","preventionTips":["Wait for service readiness (first successful query) before firing the real queries in tests","Validate chain IDs and field names once — a bad query fails all retries by construction","Watch the per-attempt warn logs: they contain the actual GraphQL errors, the bail only counts attempts"],"tags":["graphql","node-service","retry","cli-wrappers"],"backgroundTag":"graphql-query-failed","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}