{"record":{"id":"a1462d68f15a7eac","repo":"nautechsystems/nautilus_trader","slug":"failed-to-create-stream","errorCode":null,"errorMessage":"Failed to create stream","messagePattern":"Failed to create stream","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/hypersync/client.rs","lineNumber":250,"sourceCode":"        from_block: u64,\n        to_block: Option<u64>,\n        contract_address: &Address,\n        topics: Vec<&str>,\n    ) -> impl Stream<Item = PoolEventStreamItem> + use<> {\n        let query = Self::construct_contract_events_query(\n            from_block,\n            to_block,\n            &[*contract_address],\n            &topics,\n        );\n\n        let chain = self.chain.name;\n        let mut rx = self\n            .client\n            .clone()\n            .stream(query, StreamConfig::default())\n            .await\n            .expect(\"Failed to create stream\");\n\n        async_stream::stream! {\n              while let Some(response) = rx.recv().await {\n                let response = response.unwrap();\n                for item in pool_events_from_response(chain, response.data.blocks, response.data.logs) {\n                    yield item;\n                }\n            }\n        }\n    }\n\n    /// Disconnects from the HyperSync service and stops all background tasks.\n    pub async fn disconnect(&mut self) {\n        log::debug!(\"Disconnecting HyperSync client\");\n        self.cancellation_token.cancel();\n\n        if let Some(outcome) = finish_task(\n            &mut self.blocks_task,","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/hypersync/client.rs#L232-L268","documentation":"In `request_contract_events_stream`, the code calls `client.clone().stream(query, StreamConfig::default()).await.expect(\"Failed to create stream\")` to open a HyperSync event stream. The `stream` call is async and returns a `Result`; it fails when the query is rejected or the remote HyperSync endpoint cannot establish the stream (auth rejection, bad query shape, unreachable host). Since the panic occurs inside a public method that returns a stream, any stream-setup failure crashes the caller rather than yielding an error item.","triggerScenarios":"Calling `request_contract_events_stream` when the HyperSync endpoint rejects the query/stream setup: invalid or revoked API token, malformed query (bad range/topic/filter combination), endpoint downtime or network failure, or a URL pointing at a non-responsive host.","commonSituations":"Network outages or firewall blocks while opening a live subscription; query asking for a block range or topic set the endpoint refuses; rate limits or account issues causing auth rejection at stream open; stale test infrastructure hitting an unreachable HyperSync host.","solutions":["Verify network reachability and that the HyperSync endpoint URL is correct and up.","Confirm `ENVIO_API_TOKEN` is a valid, active UUID — auth failures surface at stream creation.","Validate the query (block range, topics, contract addresses) against the hypersync-client schema for your version.","Restructure the call site to `match`/`?` the `stream(...)` result and surface a `Retryable`/error outcome instead of `expect`.","Add retry with backoff around stream creation for transient endpoint failures."],"exampleFix":"// before\nlet mut rx = self.client.clone().stream(query, StreamConfig::default()).await\n    .expect(\"Failed to create stream\");\n// after\nlet mut rx = self.client.clone().stream(query, StreamConfig::default()).await\n    .map_err(|e| anyhow::anyhow!(\"hypersync stream setup failed: {e}\"))?;","handlingStrategy":"try-catch","validationCode":"// Pre-flight: confirm the endpoint accepts a cheap request before opening a long stream\nlet probe = reqwest::get(format!(\"{}/health\", chain.hypersync_url.trim_end_matches('/')))\n    .await\n    .map_err(|e| anyhow::anyhow!(\"hypersync endpoint unreachable: {e}\"))?;\nanyhow::ensure!(probe.status().is_success(), \"hypersync health check failed\");","typeGuard":null,"tryCatchPattern":"// Replace expect with Result mapping and retry transient failures\nmatch self.client.clone().stream(query, StreamConfig::default()).await {\n    Ok(rx) => rx,\n    Err(e) if e.is_retryable() => /* backoff and retry */,\n    Err(e) => return Err(anyhow::anyhow!(\"hypersync stream setup failed: {e}\")),\n}","preventionTips":["Health-check the endpoint before subscribing to long-running streams.","Keep the query within schema limits (block ranges, topic counts) for your hypersync-client version.","Wrap stream creation in bounded retry with backoff for transient errors.","Monitor token validity/rotation so auth rejections are caught early."],"tags":["panic","rust","hypersync","streaming","network"],"backgroundTag":"http-request-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}