{"record":{"id":"2ec9a48703aacb30","repo":"hyperledger/fabric","slug":"s-s","errorCode":null,"errorMessage":"%s: %s","messagePattern":"%s: %s","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/platforms/util/writer.go","lineNumber":111,"sourceCode":"\t}\n\n\tif err := filepath.Walk(rootDirectory, walkFn); err != nil {\n\t\tlogger.Infof(\"Error walking rootDirectory: %s\", err)\n\t\treturn err\n\t}\n\n\tif !success {\n\t\treturn errors.Errorf(\"no source files found in '%s'\", srcPath)\n\t}\n\treturn nil\n}\n\n// WriteFileToPackage writes a file to a tar stream.\nfunc WriteFileToPackage(localpath string, packagepath string, tw *tar.Writer) error {\n\tlogger.Debug(\"Writing file to tarball:\", packagepath)\n\tfd, err := os.Open(localpath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s: %s\", localpath, err)\n\t}\n\tdefer fd.Close()\n\n\tfi, err := fd.Stat()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s: %s\", localpath, err)\n\t}\n\n\theader, err := tar.FileInfoHeader(fi, localpath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed calculating FileInfoHeader: %s\", err)\n\t}\n\n\t// Take the variance out of the tar by using zero time and fixed uid/gid.\n\tvar zeroTime time.Time\n\theader.AccessTime = zeroTime\n\theader.ModTime = zeroTime\n\theader.ChangeTime = zeroTime","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/platforms/util/writer.go#L93-L129","documentation":"WriteFileToPackage opens localpath and writes it into a tar stream (packagepath). This error wraps os.Open failures: the local file could not be opened, and the message carries the path plus the underlying error. It is thrown early, before any tar writing starts.","triggerScenarios":"os.Open(localpath) fails because the file does not exist, the path is a directory, or the process lacks read permission.","commonSituations":"Packaging a chaincode whose build artifacts are missing (e.g. the code package path was misconfigured), running the peer as a user without read access to source files, or a typo/relative-path mistake in the deployment payload path.","solutions":["Verify the file at localpath exists (ls -l) and fix the path passed to WriteFileToPackage / GetDeploymentPayload","Check read permissions on the file and that the peer process user can access it (and every parent directory)","If packaging a directory of sources, ensure the build step that produces the file ran before packaging"],"exampleFix":"// before\nerr := util.WriteFileToPackage(missingArtifact, pkgPath, tw)\n// after\nif _, statErr := os.Stat(artifactPath); statErr != nil {\n    return fmt.Errorf(\"artifact %s not found, run build first: %w\", artifactPath, statErr)\n}\nerr := util.WriteFileToPackage(artifactPath, pkgPath, tw)","handlingStrategy":"validation","validationCode":"func canPackage(localpath string) error {\n    fi, err := os.Stat(localpath)\n    if err != nil { return fmt.Errorf(\"cannot stat %s: %w\", localpath, err) }\n    if fi.IsDir() { return fmt.Errorf(\"%s is a directory\", localpath) }\n    f, err := os.Open(localpath)\n    if err != nil { return fmt.Errorf(\"cannot open %s: %w\", localpath, err) }\n    f.Close()\n    return nil\n}","typeGuard":"func isReadableFile(path string) bool {\n    fi, err := os.Stat(path)\n    return err == nil && fi.Mode().IsRegular()\n}","tryCatchPattern":"if err := util.WriteFileToPackage(localpath, pkgPath, tw); err != nil {\n    var pe *os.PathError\n    if errors.As(err, &pe) {\n        return fmt.Errorf(\"package input unusable: %s: %w\", pe.Path, pe.Err)\n    }\n    return err\n}","preventionTips":["os.Stat the input path before packaging and fail fast with a clear message","Run the peer/packaging process with a user that has read access to the source tree","Verify build artifacts exist before invoking GetDeploymentPayload","Use absolute paths to avoid cwd-dependent failures"],"tags":["go","filesystem","tar-packaging","chaincode"],"backgroundTag":"file-not-found","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"}