{"record":{"id":"45ba8bd59bb52642","repo":"ipfs/kubo","slug":"failed-to-open-repo-w","errorCode":null,"errorMessage":"failed to open repo: %w","messagePattern":"failed to open repo: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/diag.go","lineNumber":138,"sourceCode":"\t},\n}\n\nconst diagDatastoreHexOptionName = \"hex\"\n\ntype diagDatastoreGetResult struct {\n\tKey     string `json:\"key\"`\n\tValue   []byte `json:\"value\"`\n\tHexDump string `json:\"hex_dump,omitempty\"`\n}\n\n// openDiagDatastore opens the repo datastore and conditionally mounts any\n// provider keystore datastores that exist on disk. It returns the composite\n// datastore and a cleanup function that must be called when done.\nfunc openDiagDatastore(env cmds.Environment) (datastore.Datastore, func(), error) {\n\tcctx := env.(*oldcmds.Context)\n\trepo, err := fsrepo.Open(cctx.ConfigRoot)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to open repo: %w\", err)\n\t}\n\n\textraMounts, extraCloser, err := node.MountKeystoreDatastores(repo)\n\tif err != nil {\n\t\trepo.Close()\n\t\treturn nil, nil, err\n\t}\n\n\tcloser := func() {\n\t\textraCloser()\n\t\trepo.Close()\n\t}\n\n\tif len(extraMounts) == 0 {\n\t\treturn repo.Datastore(), closer, nil\n\t}\n\n\tmounts := []mount.Mount{{Prefix: datastore.NewKey(\"/\"), Datastore: repo.Datastore()}}","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/diag.go#L120-L156","documentation":"openDiagDatastore opens the node's fsrepo directly (read-only datastore inspection by `ipfs diag datastore` commands); if fsrepo.Open(cctx.ConfigRoot) fails, the error is wrapped as 'failed to open repo'. The diag command needs standalone repo access and cannot proceed.","triggerScenarios":"Running `ipfs diag datastore get/put` while the repo cannot be opened: another daemon holds the repo lock, IPFS_PATH is wrong, or the repo is corrupted/mismatched version.","commonSituations":"Trying to inspect the datastore while the daemon is running (lock contention); wrong IPFS_PATH; repo initialized by a newer kubo version.","solutions":["Stop the running daemon before using `ipfs diag datastore` commands","Confirm IPFS_PATH points at the correct, initialized repo","Check repo lock files and version compatibility; run `ipfs repo fsck` if locks are stale"],"exampleFix":"// before\nipfs diag datastore get /some/key   # while daemon running -> failed to open repo\n// after\nipfs shutdown\nipfs diag datastore get /some/key","handlingStrategy":"validation","validationCode":"if daemonRunning() { stopDaemon() } // repo lock held otherwise\nos.Stat(filepath.Join(ipfsPath, \"datastore\")) // ensure repo exists","typeGuard":null,"tryCatchPattern":"ds, cleanup, err := openDiagDatastore(env)\nif err != nil && strings.Contains(err.Error(), \"failed to open repo\") { checkLockAndPath(); return }","preventionTips":["Stop the daemon before repo-level datastore inspection","Confirm IPFS_PATH is set to the intended repo","Use `ipfs repo fsck` to clear stale locks"],"tags":["repo","datastore","lock","cli"],"backgroundTag":"repo-open-failed","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}