{"record":{"id":"9fda77798281ab32","repo":"nautechsystems/nautilus_trader","slug":"lighter-api-key-index-must-be-in-0-254","errorCode":null,"errorMessage":"Lighter API key index must be in 0..=254","messagePattern":"Lighter API key index must be in 0\\.\\.=254","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/common/credential.rs","lineNumber":316,"sourceCode":"            .map(|s| {\n                s.trim()\n                    .parse::<u64>()\n                    .with_context(|| format!(\"{env_var} must be an unsigned integer\"))\n            })\n            .transpose(),\n    }\n}\n\nfn parse_api_key_index(value: &str, env_var: &str) -> anyhow::Result<u8> {\n    let index = value\n        .trim()\n        .parse::<u8>()\n        .with_context(|| format!(\"{env_var} must be an API key index in 0..=254\"))?;\n    ensure_api_key_index(index)\n}\n\nfn ensure_api_key_index(value: u8) -> anyhow::Result<u8> {\n    anyhow::ensure!(value <= 254, \"Lighter API key index must be in 0..=254\");\n    Ok(value)\n}\n\nfn decode_private_key_hex(value: &str) -> anyhow::Result<Vec<u8>> {\n    let value = value.trim();\n    let hex = value\n        .strip_prefix(\"0x\")\n        .or_else(|| value.strip_prefix(\"0X\"))\n        .unwrap_or(value);\n    let bytes = hex::decode(hex).context(\"Lighter API secret must be valid hex\")?;\n    anyhow::ensure!(\n        bytes.len() == SCALAR_BYTES,\n        \"Lighter API secret must be a 40-byte hex private key\"\n    );\n    Ok(bytes)\n}\n\n#[cfg(test)]","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/common/credential.rs#L298-L334","documentation":"The Lighter credential loader validates that the API key index is a u8 in the range 0..=254 (255 is reserved). `ensure_api_key_index` rejects any value above 254 with this error. The index is read from an environment variable or passed directly by `new`, `resolve_api_key_index`, or `parse_api_key_index`.","triggerScenarios":"Setting the Lighter API key index env var to a value like `255` or any integer > 254, or calling `new`/`ensure_api_key_index` with an out-of-range index.","commonSituations":"Typos or misconfigured credentials in the environment; copying an index from a different system that allows 255; misunderstanding that 255 is reserved by the Lighter API.","solutions":["Set the API key index env var to an integer between 0 and 254 inclusive.","Confirm with your Lighter account which API key indices are actually provisioned and use one of those.","Re-read the documentation: 255 is reserved and never valid."],"exampleFix":"// before\nLIGHTER_API_KEY_INDEX=255\n// after\nLIGHTER_API_KEY_INDEX=2","handlingStrategy":"validation","validationCode":"let idx: u8 = std::env::var(\"LIGHTER_API_KEY_INDEX\")?.parse()?;\nassert!(idx <= 254, \"Lighter API key index must be in 0..=254\");","typeGuard":"fn is_valid_api_key_index(v: u8) -> bool { v <= 254 }","tryCatchPattern":"let creds = LighterCredentials::from_env().map_err(|e| {\n    eprintln!(\"Lighter credential config error: {e:#}\");\n    e\n})?;","preventionTips":["Validate env vars at startup with a config preflight check.","Document that index 255 is reserved.","Keep Lighter credential env vars in a validated .env or secrets manager."],"tags":["config","validation","range","lighter","credentials"],"backgroundTag":"value-out-of-range","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"}