ipfs/kubo · error

failed to get repo path: %w

Error message

failed to get repo path: %w

What it means

newAutoConfClient needs the repo path to build the AutoConf cache directory and calls config.PathRoot() to get it. If PathRoot fails (it resolves IPFS_PATH / the repo root), the error is wrapped as 'failed to get repo path: %w'. The underlying error is what matters — typically the repo path could not be determined from the environment or flags.

Source

Thrown at config/autoconf_client.go:37

	clientCache *autoconf.Client
	clientErr   error
)

// GetAutoConfClient returns a cached autoconf client or creates a new one.
// This is thread-safe and uses a singleton pattern.
func GetAutoConfClient(cfg *Config) (*autoconf.Client, error) {
	clientOnce.Do(func() {
		clientCache, clientErr = newAutoConfClient(cfg)
	})
	return clientCache, clientErr
}

// newAutoConfClient creates a new autoconf client with the given config
func newAutoConfClient(cfg *Config) (*autoconf.Client, error) {
	// Get repo path for cache directory
	repoPath, err := PathRoot()
	if err != nil {
		return nil, fmt.Errorf("failed to get repo path: %w", err)
	}

	// Prepare refresh interval with nil check
	refreshInterval := cfg.AutoConf.RefreshInterval
	if refreshInterval == nil {
		refreshInterval = &OptionalDuration{}
	}

	// Use default URL if not specified
	url := cfg.AutoConf.URL.WithDefault(DefaultAutoConfURL)

	// Build client options
	options := []autoconf.Option{
		autoconf.WithCacheDir(filepath.Join(repoPath, "autoconf")),
		autoconf.WithUserAgent(version.GetUserAgentVersion()),
		autoconf.WithCacheSize(DefaultAutoConfCacheSize),
		autoconf.WithTimeout(DefaultAutoConfTimeout),
		autoconf.WithRefreshInterval(refreshInterval.WithDefault(DefaultAutoConfRefreshInterval)),

View on GitHub (pinned to 329838acdf)

Solutions

  1. Inspect the wrapped '%w' cause with errors.Unwrap to see why PathRoot failed
  2. Set/fix the IPFS_PATH environment variable to a writable directory
  3. Initialize the repo (ipfs init) at the configured path before starting the daemon
  4. Pass an explicit --repo-dir flag if invoking the binary directly

Example fix

// before
IPFS_PATH=/nonexistent/root ipfs daemon
// after
export IPFS_PATH=~/.ipfs
ipfs init   # if not already initialized
ipfs daemon
Defensive patterns

Strategy: try-catch

Validate before calling

if os.Getenv("IPFS_PATH") == "" && !repoInitialized() { initRepo() }

Try / catch

if _, err := PathRoot(); err != nil { return fmt.Errorf("autoconf disabled: repo path unavailable: %w", err) }
client, err := newAutoConfClient(cfg)
if err != nil { var pe *PathError; if errors.As(err, &pe) { log.Warn("bad IPFS_PATH, skipping autoconf") } else { return err } }

Prevention

When it happens

Trigger: Daemon startup (or any path constructing the AutoConf client with AutoConf.Enabled) when config.PathRoot() returns an error, e.g. IPFS_PATH points somewhere unusable or the repo root cannot be resolved.

Common situations: IPFS_PATH set to an invalid/unreadable path; running in a sandboxed environment where the home directory or env vars are missing; corrupted environment when launching the daemon programmatically.

Related errors


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