ipfs/kubo · error

could not get repo version: %w

Error message

could not get repo version: %w

What it means

RunMigration needs the current fs-repo version (read from the version file in the IPFS directory) to decide whether and how to migrate. This error wraps any failure from RepoVersion, typically because the directory does not exist, is not a valid IPFS repo, or the version file is missing/unreadable.

Source

Thrown at repo/fsrepo/migrations/migrations.go:39

	// Migrations subdirectory in distribution. Empty for root (no subdir).
	distMigsRoot = ""
	distFSRM     = "fs-repo-migrations"
)

// RunMigration finds, downloads, and runs the individual migrations needed to
// migrate the repo from its current version to the target version.
//
// Deprecated: This function downloads migration binaries from the internet and will be removed
// in a future version. Use RunHybridMigrations for modern migrations with embedded support,
// or RunEmbeddedMigrations for repo versions ≥16.
func RunMigration(ctx context.Context, fetcher Fetcher, targetVer int, ipfsDir string, allowDowngrade bool) error {
	ipfsDir, err := CheckIpfsDir(ipfsDir)
	if err != nil {
		return err
	}
	fromVer, err := RepoVersion(ipfsDir)
	if err != nil {
		return fmt.Errorf("could not get repo version: %w", err)
	}
	if fromVer == targetVer {
		// repo already at target version number
		return nil
	}
	if fromVer > targetVer && !allowDowngrade {
		return fmt.Errorf("downgrade not allowed from %d to %d", fromVer, targetVer)
	}

	logger := log.New(os.Stdout, "", 0)

	logger.Print("Looking for suitable migration binaries.")

	migrations, binPaths, err := findMigrations(ctx, fromVer, targetVer)
	if err != nil {
		return err
	}

View on GitHub (pinned to 329838acdf)

Solutions

  1. Verify ipfsDir points to an initialized IPFS repo containing a readable version file.
  2. Check file permissions on the repo directory and the version file.
  3. If the repo is corrupted, restore from backup or re-init and re-import your data.
  4. Run `ipfs repo version` to confirm the version file is readable before migrating.

Example fix

// before
cmd.RunMigration(ctx, cfg, "", from, to, false) // ipfsDir empty/invalid
// after
os.Setenv("IPFS_PATH", "/home/user/.ipfs") // ensure valid repo dir first
cmd.RunMigration(ctx, cfg, "", from, to, false)
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(filepath.Join(ipfsDir, "version")); err != nil {
    return fmt.Errorf("not an initialized IPFS repo at %s", ipfsDir)
}

Try / catch

if err := RunMigration(ctx, cfg, ipfsDir, from, to, false); err != nil {
    if strings.Contains(err.Error(), "could not get repo version") {
        // check repo dir / run ipfs init
    }
}

Prevention

When it happens

Trigger: Calling RunMigration (directly or via RunHybridMigrations) with an ipfsDir that does not contain a version file, has wrong permissions, or whose version number cannot be parsed.

Common situations: Pointing IPFS_PATH at an empty or wrong directory; running migrations before ipfs init; a corrupted repo after a failed previous migration or disk issue.

Related errors


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/4f6379c7824daa01. Report an issue: GitHub.