{"record":{"id":"dbc0e7bc64bc99eb","repo":"o2sh/onefetch","slug":"could-not-initialize-the-license-detector","errorCode":null,"errorMessage":"Could not initialize the license detector: {}","messagePattern":"Could not initialize the license detector: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/info/license.rs","lineNumber":26,"sourceCode":"\nconst LICENSE_FILES: [&str; 3] = [\"LICENSE\", \"LICENCE\", \"COPYING\"];\n\nstatic CACHE_DATA: &[u8] = include_bytes!(concat!(\n    env!(\"CARGO_MANIFEST_DIR\"),\n    \"/resources/license.cache.zstd\"\n));\nconst MIN_THRESHOLD: f32 = 0.8;\n\npub struct Detector {\n    store: Store,\n}\n\nimpl Detector {\n    pub fn new() -> Result<Self> {\n        match Store::from_cache(CACHE_DATA) {\n            Ok(store) => Ok(Self { store }),\n            Err(e) => {\n                bail!(\"Could not initialize the license detector: {}\", e)\n            }\n        }\n    }\n\n    fn get_license(&self, dir: &Path, manifest: Option<&Manifest>) -> Result<String> {\n        let license_from_manifest = manifest.and_then(|m| m.license.clone()).unwrap_or_default();\n        if license_from_manifest.is_empty() {\n            let mut output = fs::read_dir(dir)?\n                .filter_map(std::result::Result::ok)\n                .map(|entry| entry.path())\n                .filter(|entry| {\n                    entry.is_file()\n                        && entry\n                            .file_name()\n                            .map(OsStr::to_string_lossy)\n                            .is_some_and(is_license_file)\n                })\n                .filter_map(|entry| {","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/o2sh/onefetch/blob/b566c097a12e73950e7abf693d0c10928a8dd3aa/src/info/license.rs#L8-L44","documentation":"This error is raised by Detector::new() when askalono's Store::from_cache() fails to deserialize the bundled license cache (resources/license.cache.zstd, embedded via include_bytes! at compile time). It means the license detector could not be constructed, so license detection for a repository cannot proceed. Because the cache is compiled into the binary, this almost always indicates a corrupted, truncated, missing, or incompatible cache file in the crate itself, or an askalono version mismatch producing an unreadable cache format.","triggerScenarios":"Calling onefetch's license detection (e.g. Detector::new() or any info rendering that constructs the detector) when Store::from_cache cannot decompress/parse the embedded zstd license cache — e.g. the resources/license.cache.zstd file was corrupted, replaced with an empty or invalid file, generated by an incompatible askalono version, or the include_bytes! path broke in a modified build.","commonSituations":"Building the crate after modifying or deleting resources/license.cache.zstd; regenerating the cache with a different askalono version whose cache serialization format is incompatible; a source distribution (crates.io package) missing the resources file; an interrupted or tampered build where the embedded bytes are wrong; vendored/forked builds that broke CARGO_MANIFEST_DIR-relative include_bytes! resolution.","solutions":["Verify resources/license.cache.zstd exists, is non-empty, and is a valid zstd file in the crate checkout; restore it from the upstream repo if damaged.","Run `cargo clean` and rebuild to ensure the embedded bytes match the current resource file.","Regenerate the license cache with the same askalono version the Cargo.toml depends on (askalono's cache/`store` tooling), then rebuild.","Pin or align the askalono dependency version with the version used to produce the cache; a mismatched format cannot be deserialized.","If the error persists in a fork, check that include_bytes!(concat!(env!(\"CARGO_MANIFEST_DIR\"), \"/resources/license.cache.zstd\")) points at the intended file for your build layout.","As a last resort, wrap Detector::new() and degrade gracefully (skip license info) instead of failing the whole run."],"exampleFix":"// before\nlet detector = Detector::new()?;\n// after\nlet detector = match Detector::new() {\n    Ok(d) => Some(d),\n    Err(e) => {\n        eprintln!(\"license detection unavailable: {e}\");\n        None\n    }\n};","handlingStrategy":"try-catch","validationCode":"// Before calling Detector::new(), verify the embedded cache is present and valid zstd:\nfn license_cache_looks_valid() -> bool {\n    // CACHE_DATA is include_bytes!-embedded; a healthy build always has non-empty bytes\n    !CACHE_DATA.is_empty()\n}","typeGuard":"fn detector_available() -> Option<Detector> {\n    Detector::new().ok()\n}","tryCatchPattern":"match Detector::new() {\n    Ok(detector) => detector.get_license(dir, manifest),\n    Err(e) if e.to_string().contains(\"Could not initialize the license detector\") => {\n        // fall back: report license as unknown, don't abort the whole info run\n        eprintln!(\"license detector unavailable: {e}\");\n        Ok(\"unknown\".to_string())\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Never modify or delete resources/license.cache.zstd without regenerating it with the matching askalono version.","Run `cargo clean && cargo build` after pulling dependency changes so embedded resources are re-included consistently.","Pin the askalono dependency version and regenerate the cache whenever upgrading it.","In CI, add a smoke test that calls Detector::new() so a broken cache fails the build early.","When packaging (crates.io publish, vendoring), confirm resources/ files are included in the package via `cargo package --list`."],"tags":["rust","license-detection","cache","initialization","askalono"],"backgroundTag":"module-init-failed","analyzedSha":"b566c097a12e73950e7abf693d0c10928a8dd3aa","analyzedAt":"2026-09-08T05:04:10.462Z","contentChangedAt":"2026-09-08T05:04:10.462Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}