hyperledger/fabric · error

invalid path: %s. The path for the snapshot dir is expected

Error message

invalid path: %s. The path for the snapshot dir is expected to be an absolute path

What it means

initSnapshotDir validates that the configured snapshots root directory (ledger.snapshots.rootDir in core.yaml) is an absolute path. Relative paths would resolve unpredictably relative to the peer's working directory, so NewProvider fails fast with this error.

Source

Thrown at core/ledger/kvledger/kv_ledger_provider.go:251

	sysNamespaces := p.initializer.DeployedChaincodeInfoProvider.Namespaces()
	p.dbProvider, err = privacyenabledstate.NewDBProvider(
		p.bookkeepingProvider,
		p.initializer.MetricsProvider,
		p.initializer.HealthCheckRegistry,
		stateDBConfig,
		sysNamespaces,
	)
	return err
}

func (p *Provider) initLedgerStatistics() {
	p.stats = newStats(p.initializer.MetricsProvider)
}

func (p *Provider) initSnapshotDir() error {
	snapshotsRootDir := p.initializer.Config.SnapshotsConfig.RootDir
	if !filepath.IsAbs(snapshotsRootDir) {
		return errors.Errorf("invalid path: %s. The path for the snapshot dir is expected to be an absolute path", snapshotsRootDir)
	}

	inProgressSnapshotsPath := SnapshotsTempDirPath(snapshotsRootDir)
	completedSnapshotsPath := CompletedSnapshotsPath(snapshotsRootDir)

	if err := os.RemoveAll(inProgressSnapshotsPath); err != nil {
		return errors.Wrapf(err, "error while deleting the dir: %s", inProgressSnapshotsPath)
	}
	if err := os.MkdirAll(inProgressSnapshotsPath, 0o755); err != nil {
		return errors.Wrapf(err, "error while creating the dir: %s, ensure peer has write access to configured ledger.snapshots.rootDir directory", inProgressSnapshotsPath)
	}
	if err := os.MkdirAll(completedSnapshotsPath, 0o755); err != nil {
		return errors.Wrapf(err, "error while creating the dir: %s, ensure peer has write access to configured ledger.snapshots.rootDir directory", completedSnapshotsPath)
	}
	return fileutil.SyncDir(snapshotsRootDir)
}

// CreateFromGenesisBlock implements the corresponding method from interface ledger.PeerLedgerProvider

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Set ledger.snapshots.rootDir to an absolute path in core.yaml (e.g. /var/hyperledger/production/snapshots)
  2. Verify with 'peer node start' config dump that the resolved value begins with '/'
  3. Fix config templates/overlays that produce a relative path

Example fix

# before (core.yaml)
ledger:
  snapshots:
    rootDir: snapshots
# after
ledger:
  snapshots:
    rootDir: /var/hyperledger/production/snapshots
Defensive patterns

Strategy: validation

Validate before calling

rootDir := viper.GetString("ledger.snapshots.rootDir")
if !filepath.IsAbs(rootDir) {
    return fmt.Errorf("ledger.snapshots.rootDir must be absolute, got %q", rootDir)
}

Prevention

When it happens

Trigger: Peer startup (NewProvider -> initSnapshotDir) with a relative value for ledger.snapshots.rootDir, e.g. 'snapshots' or './snapshots' instead of '/var/hyperledger/production/snapshots'.

Common situations: Hand-edited core.yaml, environment-specific config templates that dropped the leading slash, or container deployments mounting the snapshots dir at a path but configuring it relatively.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/3e7128a9a204e7a2. Report an issue: GitHub.