pnpm/pnpm · error

deserialize StoreDir

Error message

deserialize StoreDir

What it means

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.

Solutions

  1. Temporarily replace expect with a panic that prints the serde error to see whether it is a type mismatch or a custom validator failure.
  2. Confirm StoreDir's Deserialize path accepts any path string and appends the version only when missing (mirroring `From<PathBuf>`).
  3. Check the crate's serde `derive` feature and serde_json versions align in Cargo.lock.
  4. Validate the JSON literal is a plain quoted string, not an object or unquoted path.
  5. Round-trip a StoreDir through `serde_json::to_string` then `from_str` in a scratch test to isolate serialize vs deserialize.

Example fix

// before
let store: StoreDir = serde_json::from_str(json).expect("deserialize StoreDir");
// after — diagnose
let store: StoreDir = serde_json::from_str(json)
    .unwrap_or_else(|e| panic!("deserialize StoreDir: {e}"));
Defensive patterns

Strategy: type-guard

Validate before calling

fn is_json_string(s: &str) -> bool {
    serde_json::from_str::<String>(s).is_ok()
}
// call before deserializing to StoreDir
assert!(is_json_string(json), "input must be a JSON string literal");

Type guard

fn parse_store_dir(json: &str) -> Option<StoreDir> {
    serde_json::from_str::<StoreDir>(json).ok()
}

Try / catch

match serde_json::from_str::<StoreDir>(json) {
    Ok(store) => use_store(store),
    Err(e) => eprintln!("storeDir deserialization failed: {e}"),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of pnpm/pnpm@e45f033222 (2026-09-22). Data as JSON: /api/errors/6e6c1d729aba5eeb. Report an issue: GitHub.

Appendix: source

Thrown at pnpm/crates/store-dir/src/store_dir/tests.rs:68

/// which emits `\v11` on Windows, and pacquet's
/// [`From<PathBuf> for StoreDir`] matches that with `PathBuf::join`.
/// Hardcoding `/` here would compare a backslash-joined left against
/// a slash-joined right and panic on Windows only.
#[test]
fn modules_yaml_serialized_store_dir_carries_store_version() {
    let store = StoreDir::new("/tmp/.pnpm-store");
    let recorded = store.display().to_string();
    let pnpm_would_emit = Path::new("/tmp/.pnpm-store")
        .join(STORE_VERSION)
        .display()
        .to_string();
    assert_eq!(recorded, pnpm_would_emit);
}

#[test]
fn deserialize_applies_store_version_to_unsuffixed_path() {
    let json = r#""/home/user/.local/share/pnpm/store""#;
    let store: StoreDir = serde_json::from_str(json).expect("deserialize StoreDir");
    assert_eq!(store.root(), Path::new("/home/user/.local/share/pnpm/store/v11"));
}

#[test]
fn deserialize_preserves_already_suffixed_path() {
    let json = r#""/home/user/.local/share/pnpm/store/v11""#;
    let store: StoreDir = serde_json::from_str(json).expect("deserialize StoreDir");
    assert_eq!(store.root(), Path::new("/home/user/.local/share/pnpm/store/v11"));
}

#[test]
fn init_creates_all_256_shards_and_populates_cache() {
    use tempfile::tempdir;

    let tempdir = tempdir().unwrap();
    let store = StoreDir::new(tempdir.path());
    store.init().unwrap();

View on GitHub (pinned to e45f033222)