{"record":{"id":"6e6c1d729aba5eeb","repo":"pnpm/pnpm","slug":"deserialize-storedir","errorCode":null,"errorMessage":"deserialize StoreDir","messagePattern":"deserialize StoreDir","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pnpm/crates/store-dir/src/store_dir/tests.rs","lineNumber":68,"sourceCode":"/// which emits `\\v11` on Windows, and pacquet's\n/// [`From<PathBuf> for StoreDir`] matches that with `PathBuf::join`.\n/// Hardcoding `/` here would compare a backslash-joined left against\n/// a slash-joined right and panic on Windows only.\n#[test]\nfn modules_yaml_serialized_store_dir_carries_store_version() {\n    let store = StoreDir::new(\"/tmp/.pnpm-store\");\n    let recorded = store.display().to_string();\n    let pnpm_would_emit = Path::new(\"/tmp/.pnpm-store\")\n        .join(STORE_VERSION)\n        .display()\n        .to_string();\n    assert_eq!(recorded, pnpm_would_emit);\n}\n\n#[test]\nfn deserialize_applies_store_version_to_unsuffixed_path() {\n    let json = r#\"\"/home/user/.local/share/pnpm/store\"\"#;\n    let store: StoreDir = serde_json::from_str(json).expect(\"deserialize StoreDir\");\n    assert_eq!(store.root(), Path::new(\"/home/user/.local/share/pnpm/store/v11\"));\n}\n\n#[test]\nfn deserialize_preserves_already_suffixed_path() {\n    let json = r#\"\"/home/user/.local/share/pnpm/store/v11\"\"#;\n    let store: StoreDir = serde_json::from_str(json).expect(\"deserialize StoreDir\");\n    assert_eq!(store.root(), Path::new(\"/home/user/.local/share/pnpm/store/v11\"));\n}\n\n#[test]\nfn init_creates_all_256_shards_and_populates_cache() {\n    use tempfile::tempdir;\n\n    let tempdir = tempdir().unwrap();\n    let store = StoreDir::new(tempdir.path());\n    store.init().unwrap();\n","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/pnpm/pnpm/blob/e45f0332229b094d61f2ecad114a166e338c0d61/pnpm/crates/store-dir/src/store_dir/tests.rs#L50-L86","documentation":"The message \"deserialize StoreDir\" comes from `Result::expect(\"deserialize StoreDir\")` on `serde_json::from_str::<StoreDir>(json)` at pnpm/crates/store-dir/src/store_dir/tests.rs:68. Deserializing a bare store path string must apply the store-version suffix (`v11`) so the resulting root matches what pnpm compares against `.modules.yaml`; the expect fires when serde cannot build a `StoreDir` from the JSON string — a deserialize-impl error, wrong JSON shape, or serde configuration regression.","triggerScenarios":"Feeding `serde_json::from_str` a value that is not a JSON string; a `Deserialize` impl for StoreDir that rejects unsuffixed paths or requires a different shape (object/tuple); a `#[serde(try_from)]` validator returning Err; serde/serde_json feature or version mismatch.","commonSituations":"Changing StoreDir's serde wiring so a validator wrongly requires the `v11` suffix already present; reading a `.modules.yaml` or state file written by an older pnpm whose storeDir lacks the suffix; hand-edited JSON fixtures with invalid syntax.","solutions":["Temporarily replace expect with a panic that prints the serde error to see whether it is a type mismatch or a custom validator failure.","Confirm StoreDir's Deserialize path accepts any path string and appends the version only when missing (mirroring `From<PathBuf>`).","Check the crate's serde `derive` feature and serde_json versions align in Cargo.lock.","Validate the JSON literal is a plain quoted string, not an object or unquoted path.","Round-trip a StoreDir through `serde_json::to_string` then `from_str` in a scratch test to isolate serialize vs deserialize."],"exampleFix":"// before\nlet store: StoreDir = serde_json::from_str(json).expect(\"deserialize StoreDir\");\n// after — diagnose\nlet store: StoreDir = serde_json::from_str(json)\n    .unwrap_or_else(|e| panic!(\"deserialize StoreDir: {e}\"));","handlingStrategy":"type-guard","validationCode":"fn is_json_string(s: &str) -> bool {\n    serde_json::from_str::<String>(s).is_ok()\n}\n// call before deserializing to StoreDir\nassert!(is_json_string(json), \"input must be a JSON string literal\");","typeGuard":"fn parse_store_dir(json: &str) -> Option<StoreDir> {\n    serde_json::from_str::<StoreDir>(json).ok()\n}","tryCatchPattern":"match serde_json::from_str::<StoreDir>(json) {\n    Ok(store) => use_store(store),\n    Err(e) => eprintln!(\"storeDir deserialization failed: {e}\"),\n}","preventionTips":["Keep the Deserialize impl aligned with `From<PathBuf>`: append the version only when missing.","If using `#[serde(try_from = \"String\")]`, make the validator accept unsuffixed paths.","Pin serde/serde_json versions and features; review Cargo.lock drift after updates.","Validate that persisted storeDir strings are JSON string literals before parsing.","Round-trip serialize/deserialize in a scratch test whenever the serde wiring changes."],"tags":["rust","serde","deserialization","test-panic"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"e45f0332229b094d61f2ecad114a166e338c0d61","analyzedAt":"2026-09-22T05:07:20.233Z","contentChangedAt":"2026-09-22T05:07:20.233Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}