{"record":{"id":"0067830e8290ab36","repo":"spacejam/sled","slug":"db-s-leaf-fanout-const-generic-must-be-3-or-greater","errorCode":null,"errorMessage":"Db's LEAF_FANOUT const generic must be 3 or greater.","messagePattern":"Db's LEAF_FANOUT const generic must be 3 or greater\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config.rs","lineNumber":148,"sourceCode":"    pub fn path<P: AsRef<Path>>(mut self, path: P) -> Config {\n        self.path = path.as_ref().to_path_buf();\n        self\n    }\n\n    builder!(\n        (flush_every_ms, Option<usize>, \"Start a background thread that flushes data to disk every few milliseconds. Defaults to every 200ms.\"),\n        (cache_capacity_bytes, usize, \"Cache size in **bytes**. Default is 512mb.\"),\n        (entry_cache_percent, u8, \"The percentage of the cache that is dedicated to the scan-resistant entry cache.\"),\n        (zstd_compression_level, i32, \"The zstd compression level to use when writing data to disk. Defaults to 3.\"),\n        (target_heap_file_fill_ratio, f32, \"A float between 0.0 and 1.0 that controls how much fragmentation can exist in a file before GC attempts to recompact it.\"),\n        (max_inline_value_threshold, usize, \"Values larger than this configurable will be stored as separate blob\")\n    );\n\n    pub fn open<const LEAF_FANOUT: usize>(\n        &self,\n    ) -> io::Result<Db<LEAF_FANOUT>> {\n        if LEAF_FANOUT < 3 {\n            return Err(annotate!(io::Error::new(\n                io::ErrorKind::Unsupported,\n                \"Db's LEAF_FANOUT const generic must be 3 or greater.\"\n            )));\n        }\n        Db::open_with_config(self)\n    }\n}\n","sourceCodeStart":130,"sourceCodeEnd":156,"githubUrl":"https://github.com/spacejam/sled/blob/e449d17111f4a097e1c66b6db241962ccb6a4136/src/config.rs#L130-L156","documentation":"This library is generic over a const LEAF_FANOUT for its B-tree leaf nodes, and Db::open rejects any value below 3 because a leaf needs at least a valid minimum branching capacity. It is thrown eagerly at open time so an invalid database layout is never created or persisted.","triggerScenarios":"Calling Config::open::<LEAF_FANOUT>() with LEAF_FANOUT set to 0, 1, or 2 (e.g. open::<2>()) instead of an integer >= 3.","commonSituations":"Copy-pasting a small const generic during experimentation, computing the fanout from another constant that defaults to a tiny value, or typos like open::<0>() intended as a placeholder.","solutions":["Change the const generic argument to a value of 3 or greater at the Db::open call site","If the value comes from a named constant, raise that constant's definition to >= 3","Assert the fanout at compile time with a const assertion so the failure happens before open"],"exampleFix":"// before\nlet db = config.open::<2>()?;\n// after\nlet db = config.open::<4>()?;","handlingStrategy":"validation","validationCode":"const LEAF_FANOUT: usize = 4;\nconst _: () = assert!(LEAF_FANOUT >= 3, \"LEAF_FANOUT must be >= 3\");\nlet db = config.open::<LEAF_FANOUT>()?;","typeGuard":null,"tryCatchPattern":"match config.open::<FANOUT>() {\n    Ok(db) => db,\n    Err(e) if e.to_string().contains(\"LEAF_FANOUT\") => panic!(\"config bug: fanout too small\"),\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Define the fanout as a named constant with a compile-time assert (>= 3)","Never pass literal small values like 0/1/2 as the const generic","Add a unit test that opens a throwaway Db with your production fanout constant"],"tags":["rust","configuration","const-generics","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"e449d17111f4a097e1c66b6db241962ccb6a4136","analyzedAt":"2026-09-12T01:23:10.985Z","contentChangedAt":"2026-09-12T01:23:10.985Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}