{"record":{"id":"9917ff96f55c9a1a","repo":"hyperledger/fabric","slug":"could-not-determine-whether-file-s-exists","errorCode":null,"errorMessage":"could not determine whether file '%s' exists","messagePattern":"could not determine whether file '(.+?)' exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/persistence/persistence.go","lineNumber":121,"sourceCode":"}\n\n// MakeDir makes a directory on the filesystem (and any\n// necessary parent directories).\nfunc (f *FilesystemIO) MakeDir(dirname string, mode os.FileMode) error {\n\treturn os.MkdirAll(dirname, mode)\n}\n\n// Exists checks whether a file exists\nfunc (*FilesystemIO) Exists(path string) (bool, error) {\n\t_, err := os.Stat(path)\n\tif err == nil {\n\t\treturn true, nil\n\t}\n\tif os.IsNotExist(err) {\n\t\treturn false, nil\n\t}\n\n\treturn false, errors.Wrapf(err, \"could not determine whether file '%s' exists\", path)\n}\n\n// Store holds the information needed for persisting a chaincode install package\ntype Store struct {\n\tPath       string\n\tReadWriter IOReadWriter\n}\n\n// NewStore creates a new chaincode persistence store using\n// the provided path on the filesystem.\nfunc NewStore(path string) *Store {\n\tstore := &Store{\n\t\tPath:       path,\n\t\tReadWriter: &FilesystemIO{},\n\t}\n\tstore.Initialize()\n\treturn store\n}","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/persistence/persistence.go#L103-L139","documentation":"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.","triggerScenarios":"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.","commonSituations":"Permission problems on directories above the target path; symlink loops; failing network mounts during a `peer lifecycle chaincode install` or commit-time ledger check.","solutions":["Fix permissions on the parent directories so the peer process can stat the path","Check the wrapped underlying error (`%v` of the cause) for the exact errno and address it (EACCES, EIO, ELOOP...)","Repair or remount the storage backing the path if the filesystem reports I/O errors"],"exampleFix":"// before: assume exists==false means missing\nexists, _ := rw.Exists(path)\n\n// after: handle the indeterminate case\nexists, err := rw.Exists(path)\nif err != nil {\n    return fmt.Errorf(\"path check failed for %s: %w\", path, err)\n}","handlingStrategy":"try-catch","validationCode":"func checkStatAccess(p string) error {\n    if _, err := os.Stat(filepath.Dir(p)); err != nil {\n        return fmt.Errorf(\"cannot stat parent of %s: %w\", p, err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"exists, err := io.Exists(path)\nif err != nil {\n    // err wraps 'could not determine whether file ... exists'\n    if errors.Is(err, os.ErrPermission) { /* fix perms or fail fast */ }\n    return fmt.Errorf(\"existence check failed, refusing to guess: %w\", err)\n}","preventionTips":["Ensure execute (x) permission on every ancestor directory of the path","Avoid symlink chains into mounts that can go offline","Treat a non-nil error from Exists as 'unknown', never as 'missing'"],"tags":["filesystem","permissions","existence-check"],"backgroundTag":"stat-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}