{"record":{"id":"3a317c6787c51dfa","repo":"nautechsystems/nautilus_trader","slug":"invalid-cacheconfig","errorCode":null,"errorMessage":"invalid `CacheConfig`","messagePattern":"invalid `CacheConfig`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/cache/mod.rs","lineNumber":2273,"sourceCode":"        Self::new(Some(CacheConfig::default()), None)\n    }\n}\n\nimpl Cache {\n    /// Creates a new [`Cache`] instance with optional configuration and database adapter.\n    #[must_use]\n    /// # Note\n    ///\n    /// Uses provided `CacheConfig` or defaults, and optional `CacheDatabaseAdapter` for persistence.\n    ///\n    /// # Panics\n    ///\n    /// Panics if the cache config has a tick or bar capacity outside `[1, 1_000_000]`.\n    pub fn new(\n        config: Option<CacheConfig>,\n        database: Option<Box<dyn CacheDatabaseAdapter>>,\n    ) -> Self {\n        Self::try_new(config, database).expect(\"invalid `CacheConfig`\")\n    }\n\n    /// Creates a new [`Cache`] instance with optional configuration and database adapter.\n    ///\n    /// # Errors\n    ///\n    /// Returns a [`crate::config::ConfigError`] if the cache configuration is invalid.\n    pub fn try_new(\n        config: Option<CacheConfig>,\n        database: Option<Box<dyn CacheDatabaseAdapter>>,\n    ) -> crate::config::ConfigResult<Self> {\n        let config = config.unwrap_or_default();\n        config.validate()?;\n\n        Ok(Self {\n            config,\n            index: CacheIndex::default(),\n            database,","sourceCodeStart":2255,"sourceCodeEnd":2291,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/cache/mod.rs#L2255-L2291","documentation":"Cache::new unwraps Cache::try_new and panics with this message when the provided CacheConfig fails validation. The library requires tick and bar cache capacities to be within [1, 1_000_000]; any config outside that range (or otherwise rejected by try_new) makes construction a hard panic instead of returning a Result.","triggerScenarios":"Calling Cache::new(Some(config), ...) where config has tick_capacity or bar_capacity equal to 0, greater than 1_000_000, or another value rejected by CacheConfig validation inside try_new.","commonSituations":"Loading cache capacities from environment variables or config files without clamping; a default of 0 for 'unbounded'; copy-pasting a config from another system; hand-rolled struct construction bypassing CacheConfig builders.","solutions":["Validate the CacheConfig before passing it: ensure tick_capacity and bar_capacity are within [1, 1_000_000]","Use Cache::try_new instead and handle the Err to get the real validation message","Clamp or sanitize values read from env/config files (e.g. max(1).min(1_000_000))","Check the log/panic payload from try_new for which specific field was rejected"],"exampleFix":"// before\nlet cache = Cache::new(Some(config), database);\n// after\nlet cache = Cache::try_new(Some(config), database).expect(\"valid CacheConfig\");","handlingStrategy":"validation","validationCode":"fn is_valid_cache_config(cfg: &CacheConfig) -> bool {\n    (1..=1_000_000).contains(&cfg.tick_capacity)\n        && (1..=1_000_000).contains(&cfg.bar_capacity)\n}","typeGuard":null,"tryCatchPattern":"// Rust panics cannot be caught; use the fallible API instead\nlet cache = Cache::try_new(config, database)\n    .expect(\"cache config rejected — check tick/bar capacities in [1, 1_000_000]\");","preventionTips":["Always construct CacheConfig through its builder/validated constructor","Clamp capacities read from env vars or config files to [1, 1_000_000]","Prefer Cache::try_new in application code to get a real error","Add a startup assertion that logs the config before building the Cache"],"tags":["rust","panic","cache","config-validation"],"backgroundTag":"invalid-config-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}