{"record":{"id":"3f5eec0822c26f27","repo":"swc-project/swc","slug":"cap-0","errorCode":null,"errorMessage":"cap == 0","messagePattern":"cap == 0","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_loader/src/resolvers/lru.rs","lineNumber":35,"sourceCode":"}\n\nimpl<R> Default for CachingResolver<R>\nwhere\n    R: Resolve + Default,\n{\n    fn default() -> Self {\n        Self::new(40, Default::default())\n    }\n}\n\nimpl<R> CachingResolver<R>\nwhere\n    R: Resolve,\n{\n    pub fn new(cap: usize, inner: R) -> Self {\n        Self {\n            cache: Mutex::new(LruCache::new(\n                NonZeroUsize::try_from(cap).expect(\"cap == 0\"),\n            )),\n            inner,\n        }\n    }\n}\n\nimpl<R> Resolve for CachingResolver<R>\nwhere\n    R: Resolve,\n{\n    fn resolve(&self, base: &FileName, src: &str) -> Result<Resolution, Error> {\n        {\n            let mut lock = self.cache.lock();\n            //\n            if let Some(v) = lock.get(&(base.clone(), src.to_string())) {\n                return Ok(v.clone());\n            }\n        }","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_loader/src/resolvers/lru.rs#L17-L53","documentation":"CachingResolver::new asserts its cache capacity is non-zero before building the LruCache (which requires NonZeroUsize). This fires when a caller constructs a CachingResolver with cap == 0, i.e. a zero-sized cache, which the LRU implementation cannot represent; the default constructor uses 40.","triggerScenarios":"Thrown at crates/swc_ecma_loader/src/resolvers/lru.rs:35 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a capacity of at least 1 to CachingResolver::new","Use CachingResolver::default() when no specific capacity is needed (defaults to 40)","If zero caching is desired, use the inner resolver directly instead of the caching wrapper"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}