hyperledger/fabric · error

could not determine whether file '%s' exists

Error message

could not determine whether file '%s' exists

What it means

FilesystemIO.Exists uses os.Stat to test whether a file exists. If stat fails with an error that is neither nil nor os.IsNotExist, the outcome is unknown and this wrapped error is returned instead of a true/false answer.

Source

Thrown at core/chaincode/persistence/persistence.go:121

}

// MakeDir makes a directory on the filesystem (and any
// necessary parent directories).
func (f *FilesystemIO) MakeDir(dirname string, mode os.FileMode) error {
	return os.MkdirAll(dirname, mode)
}

// Exists checks whether a file exists
func (*FilesystemIO) Exists(path string) (bool, error) {
	_, err := os.Stat(path)
	if err == nil {
		return true, nil
	}
	if os.IsNotExist(err) {
		return false, nil
	}

	return false, errors.Wrapf(err, "could not determine whether file '%s' exists", path)
}

// Store holds the information needed for persisting a chaincode install package
type Store struct {
	Path       string
	ReadWriter IOReadWriter
}

// NewStore creates a new chaincode persistence store using
// the provided path on the filesystem.
func NewStore(path string) *Store {
	store := &Store{
		Path:       path,
		ReadWriter: &FilesystemIO{},
	}
	store.Initialize()
	return store
}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Fix permissions on the parent directories so the peer process can stat the path
  2. Check the wrapped underlying error (`%v` of the cause) for the exact errno and address it (EACCES, EIO, ELOOP...)
  3. Repair or remount the storage backing the path if the filesystem reports I/O errors

Example fix

// before: assume exists==false means missing
exists, _ := rw.Exists(path)

// after: handle the indeterminate case
exists, err := rw.Exists(path)
if err != nil {
    return fmt.Errorf("path check failed for %s: %w", path, err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

func checkStatAccess(p string) error {
    if _, err := os.Stat(filepath.Dir(p)); err != nil {
        return fmt.Errorf("cannot stat parent of %s: %w", p, err)
    }
    return nil
}

Try / catch

exists, err := io.Exists(path)
if err != nil {
    // err wraps 'could not determine whether file ... exists'
    if errors.Is(err, os.ErrPermission) { /* fix perms or fail fast */ }
    return fmt.Errorf("existence check failed, refusing to guess: %w", err)
}

Prevention

When it happens

Trigger: Calling Exists (directly, via Store.Drop, or via verifyLedgerDoesNotExist) with a path whose parent directory is unreadable, on a filesystem returning unusual errors (EACCES, EIO, ELOOP), or with a malformed path.

Common situations: Permission problems on directories above the target path; symlink loops; failing network mounts during a `peer lifecycle chaincode install` or commit-time ledger check.

Related errors


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