{"record":{"id":"5029a5e4d4d4ab82","repo":"nautechsystems/nautilus_trader","slug":"failed-to-create-hypersync-client-check-envio-ap","errorCode":null,"errorMessage":"Failed to create HyperSync client - check ENVIO_API_TOKEN is a valid UUID","messagePattern":"Failed to create HyperSync client - check ENVIO_API_TOKEN is a valid UUID","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/adapters/blockchain/src/hypersync/client.rs","lineNumber":115,"sourceCode":"    /// Panics if:\n    /// - The chain's `hypersync_url` is invalid.\n    /// - The `ENVIO_API_TOKEN` environment variable is not set or invalid.\n    /// - The underlying client cannot be initialized.\n    #[must_use]\n    pub fn new(\n        chain: SharedChain,\n        tx: Option<tokio::sync::mpsc::UnboundedSender<BlockchainMessage>>,\n        cancellation_token: tokio_util::sync::CancellationToken,\n    ) -> Self {\n        let mut config = hypersync_client::ClientConfig::default();\n        let hypersync_url = validate_execution_endpoint(chain.hypersync_url.as_str(), \"HyperSync\")\n            .expect(\"Invalid HyperSync URL\");\n        config.url = hypersync_url.to_string();\n        config.api_token = std::env::var(\"ENVIO_API_TOKEN\")\n            .expect(\"ENVIO_API_TOKEN environment variable must be set\");\n\n        let client = hypersync_client::Client::new(config)\n            .expect(\"Failed to create HyperSync client - check ENVIO_API_TOKEN is a valid UUID\");\n\n        Self {\n            chain,\n            client: Arc::new(client),\n            blocks_task: TaskSlot::new(),\n            blocks_cancellation_token: None,\n            dex_event_tasks: AHashMap::new(),\n            tx,\n            pool_addresses: AHashMap::new(),\n            cancellation_token,\n        }\n    }\n\n    #[must_use]\n    pub fn get_pool_address(&self, instrument_id: InstrumentId) -> Option<&Address> {\n        self.pool_addresses.get(&instrument_id)\n    }\n","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/hypersync/client.rs#L97-L133","documentation":"After loading the config, `HypersyncClient::new` calls `hypersync_client::Client::new(config).expect(\"Failed to create HyperSync client - check ENVIO_API_TOKEN is a valid UUID\")`. The underlying client constructor returns a `Result` and fails when the provided `ENVIO_API_TOKEN` is not the valid UUID the Envio API expects (or the client cannot be initialized at all). Because the wrapper cannot return `Result`, an invalid token aborts the process at construction time. Note the token is read successfully here — it exists, but its value is wrong.","triggerScenarios":"Setting `ENVIO_API_TOKEN` to a placeholder, truncated value, non-UUID string, empty string, or a revoked/expired token, then constructing the HyperSync client.","commonSituations":"A dummy token copied from documentation; quotes/whitespace or a newline accidentally included in the env value; a token regenerated server-side so the old one is revoked; pasting a non-Envio API key by mistake.","solutions":["Set `ENVIO_API_TOKEN` to the exact UUID-formatted token from your Envio account, without quotes or stray whitespace.","Regenerate the token in the Envio dashboard if it may have been revoked, and update the environment.","Strip whitespace/newlines from the value at the source (e.g. `.trim()` when reading dotenv files).","Handle the underlying `Client::new` error explicitly in your own setup to get the detailed message instead of the panic."],"exampleFix":"// before\nENVIO_API_TOKEN=my-token-here cargo run   # panics: not a valid UUID\n// after\nENVIO_API_TOKEN=550e8400-e29b-41d4-a716-446655440000 cargo run","handlingStrategy":"validation","validationCode":"fn validate_envio_token_format() -> Result<(), String> {\n    let token = std::env::var(\"ENVIO_API_TOKEN\").map_err(|_| \"ENVIO_API_TOKEN not set\".to_string())?;\n    let t = token.trim();\n    let is_uuid = t.len() == 36\n        && t.chars().enumerate().all(|(i, c)| {\n            matches!(i, 8 | 13 | 18 | 23) == (c == '-')\n                && (c == '-' || c.is_ascii_hexdigit())\n        });\n    if is_uuid { Ok(()) } else { Err(\"ENVIO_API_TOKEN must be a UUID\".to_string()) }\n}","typeGuard":null,"tryCatchPattern":"// Reject malformed tokens before client construction\nvalidate_envio_token_format().map_err(|e| anyhow::anyhow!(e))?;","preventionTips":["Copy tokens without surrounding quotes; trim trailing newlines from dotenv values.","Regenerate tokens after rotation and update all environments at once.","Validate UUID format in a smoke test that runs before integration suites."],"tags":["panic","rust","hypersync","authentication","api-token","configuration"],"backgroundTag":"missing-api-key","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"}