{"record":{"id":"b55310bc4b16fc1a","repo":"nautechsystems/nautilus_trader","slug":"envio-api-token-environment-variable-must-be-set","errorCode":null,"errorMessage":"ENVIO_API_TOKEN environment variable must be set","messagePattern":"ENVIO_API_TOKEN environment variable must be set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/adapters/blockchain/src/hypersync/client.rs","lineNumber":112,"sourceCode":"    ///\n    /// # Panics\n    ///\n    /// 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> {","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/hypersync/client.rs#L94-L130","documentation":"`HypersyncClient::new` reads the HyperSync API token with `std::env::var(\"ENVIO_API_TOKEN\").expect(\"ENVIO_API_TOKEN environment variable must be set\")`, panicking when the variable is absent from the process environment. HyperSync requires an Envio API token (a UUID) for authenticated access, and since the constructor cannot return `Result`, a missing token aborts the process. The variable must be exported before the process starts; setting it at runtime within the process is too late.","triggerScenarios":"Constructing the HyperSync client in a process launched without `ENVIO_API_TOKEN` exported in its environment — e.g. running tests, a binary, or a container where the variable was never set.","commonSituations":"Running `cargo test` locally without a `.env`/shell export; CI pipelines lacking the secret; Docker/Kubernetes deployments missing the env var; a typo like `ENVIO_API_TOKEN` vs `ENVIO_TOKEN`.","solutions":["Export `ENVIO_API_TOKEN=<your-uuid-token>` in the shell or service environment before starting the process.","Add the variable to your CI secret store and deployment manifests.","In local dev, source a `.env` file (e.g. with dotenvy) or export it in your shell profile.","Fail fast in your own bootstrap code: check `std::env::var(\"ENVIO_API_TOKEN\")` and emit a clear message before constructing the client."],"exampleFix":"// before\nlet client = HypersyncClient::new(chain, tx, token); // panics if ENVIO_API_TOKEN unset\n// after\nif std::env::var(\"ENVIO_API_TOKEN\").is_err() {\n    anyhow::bail!(\"ENVIO_API_TOKEN must be set to use HyperSync\");\n}\nlet client = HypersyncClient::new(chain, tx, token);","handlingStrategy":"validation","validationCode":"fn require_envio_token() -> Result<String, String> {\n    std::env::var(\"ENVIO_API_TOKEN\")\n        .ok()\n        .filter(|t| !t.trim().is_empty())\n        .map(|t| t.trim().to_string())\n        .ok_or_else(|| \"ENVIO_API_TOKEN must be exported before starting\".to_string())\n}","typeGuard":null,"tryCatchPattern":"// Check at process startup, not inside the client constructor\nlet _token = require_envio_token().map_err(|e| { eprintln!(\"{e}\"); std::process::exit(1) });","preventionTips":["Document ENVIO_API_TOKEN in the project README/setup script and check it in a startup assertion.","Add the secret to CI and container env configuration before running integration tests.","Use dotenvy locally and commit a `.env.example` listing required variables."],"tags":["panic","rust","environment-variable","hypersync","configuration","api-token"],"backgroundTag":"missing-env-var","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"}