{"record":{"id":"e16c5885352879f1","repo":"ipfs/kubo","slug":"could-not-get-current-repo-version-w","errorCode":null,"errorMessage":"could not get current repo version: %w","messagePattern":"could not get current repo version: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/fsrepo/migrations/migrations.go","lineNumber":347,"sourceCode":"// 2. Uses embedded migrations for v16+ steps\n// 3. Handles pure external, pure embedded, or mixed migration scenarios\n//\n// Legacy external migrations (repo versions <16) only support HTTPS downloads.\n//\n// Parameters:\n//   - ctx: Context for cancellation and timeouts\n//   - targetVer: Target repository version to migrate to\n//   - ipfsDir: Path to the IPFS repository directory\n//   - allowDowngrade: Whether to allow downgrade migrations\n//\n// Returns error if migration fails at any step.\nfunc RunHybridMigrations(ctx context.Context, targetVer int, ipfsDir string, allowDowngrade bool) error {\n\tconst embeddedMigrationsMinVersion = 16\n\n\t// Get current repo version\n\tcurrentVer, err := RepoVersion(ipfsDir)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not get current repo version: %w\", err)\n\t}\n\n\tvar logger = log.New(os.Stdout, \"\", 0)\n\n\t// Check if migration is needed\n\tif currentVer == targetVer {\n\t\tlogger.Printf(\"Repository is already at version %d\", targetVer)\n\t\treturn nil\n\t}\n\n\t// Validate downgrade request\n\tif targetVer < currentVer && !allowDowngrade {\n\t\treturn fmt.Errorf(\"downgrade from version %d to %d requires allowDowngrade=true\", currentVer, targetVer)\n\t}\n\n\t// Determine migration strategy based on version ranges\n\tneedsExternal := currentVer < embeddedMigrationsMinVersion\n\tneedsEmbedded := targetVer >= embeddedMigrationsMinVersion","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/repo/fsrepo/migrations/migrations.go#L329-L365","documentation":"RunHybridMigrations first reads the current repository version from the version file in ipfsDir. If that read fails (RepoVersion error), the migration cannot proceed, and the underlying error is wrapped with this message.","triggerScenarios":"Calling RunHybridMigrations (or starting the daemon with --migrate) when IPFS_PATH/version is missing, unreadable, corrupted, or contains a non-integer; or ipfsDir points to a non-existent/uninitialized repo.","commonSituations":"Repo directory deleted or moved while daemon is stopped; manual edits to the version file; permission problems after running the daemon as different users; running migration against the wrong path.","solutions":["Verify IPFS_PATH exists and contains a valid `version` file with an integer","Run `ipfs repo version` to see if the repo itself is readable","Fix permissions: ensure the user running the daemon owns IPFS_PATH and its files","If the repo is uninitialized, run `ipfs init` instead of migrating; never hand-create the version file"],"exampleFix":"// before\nerr := migration.RunHybridMigrations(ctx, 17, \"/wrong/path\", false)\n// after\ndir := os.Getenv(\"IPFS_PATH\") // e.g. ~/.ipfs\nif _, err := os.Stat(filepath.Join(dir, \"version\")); err != nil {\n    log.Fatal(\"repo missing or uninitialized at \", dir)\n}\nerr := migration.RunHybridMigrations(ctx, 17, dir, false)","handlingStrategy":"validation","validationCode":"verFile := filepath.Join(ipfsDir, \"version\")\ndata, err := os.ReadFile(verFile)\nif err != nil { log.Fatalf(\"repo missing/unreadable: %v\", err) }\nif _, err := strconv.Atoi(strings.TrimSpace(string(data))); err != nil {\n    log.Fatalf(\"corrupt version file %s: %q\", verFile, data)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"could not get current repo version\") {\n    return fmt.Errorf(\"check IPFS_PATH (%s): repo may be missing, corrupt, or locked: %w\", ipfsDir, err)\n}","preventionTips":["Never hand-edit the repo `version` file","Run `ipfs repo version` before migrations as a sanity check","Ensure consistent user ownership of IPFS_PATH","Confirm the daemon is stopped before migrating"],"tags":["migrations","repo-version","filesystem"],"backgroundTag":"repo-version-unreadable","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"}