{"record":{"id":"9f80c49e25824429","repo":"hyperledger/fabric","slug":"error-writing-s-to-tar-s","errorCode":null,"errorMessage":"Error writing %s to tar: %s","messagePattern":"Error writing (.+?) to tar: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/platforms/golang/platform.go","lineNumber":175,"sourceCode":"\n\t// Create directories so they get sane ownership and permissions\n\tfor _, dirname := range fileMap.Directories() {\n\t\terr := tw.WriteHeader(&tar.Header{\n\t\t\tTypeflag: tar.TypeDir,\n\t\t\tName:     dirname + \"/\",\n\t\t\tMode:     c_ISDIR | 0o755,\n\t\t\tUid:      500,\n\t\t\tGid:      500,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\tfor _, file := range fileMap.Sources() {\n\t\terr = util.WriteFileToPackage(file.Path, file.Name, tw)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"Error writing %s to tar: %s\", file.Name, err)\n\t\t}\n\t}\n\n\terr = tw.Close()\n\tif err == nil {\n\t\terr = gw.Close()\n\t}\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"failed to create tar for chaincode\")\n\t}\n\n\treturn payload.Bytes(), nil\n}\n\nfunc (p *Platform) GenerateDockerfile() (string, error) {\n\tvar buf []string\n\tbuf = append(buf, \"FROM \"+util.GetDockerImageFromConfig(\"chaincode.golang.runtime\"))\n\tbuf = append(buf, \"ADD binpackage.tar /usr/local/bin\")","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/platforms/golang/platform.go#L157-L193","documentation":"GetDeploymentPayload builds a tar.gz of the chaincode sources; when util.WriteFileToPackage fails while adding a source file to the tar writer, the file name and underlying error are wrapped in this message. It indicates the package could not be produced.","triggerScenarios":"Calling GetDeploymentPayload when a discovered source file cannot be written to the tar, e.g. the file disappeared between walking and writing, permission denied reading it, or the tar/gzip writer is in an error state.","commonSituations":"Files deleted during packaging, unreadable files due to permissions, disk-full or closed-writer errors during streaming.","solutions":["Check the wrapped %s error to identify the underlying cause (permissions, missing file, I/O).","Re-run the packaging step; ensure source files exist and are readable by the process.","Verify the file name does not exceed tar name limits or contain invalid characters.","Check disk space and that the output buffer/writer is valid."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"for _, f := range files {\n\tif _, err := os.Stat(f); err != nil { return fmt.Errorf(\"missing source: %s\", f) }\n}","typeGuard":null,"tryCatchPattern":"payload, err := platform.GetDeploymentPayload(path, code)\nif err != nil {\n\tif strings.Contains(err.Error(), \"Error writing\") {\n\t\t// inspect wrapped cause: permissions, missing file, disk space\n\t\treturn fmt.Errorf(\"packaging failed: %w\", err)\n\t}\n}","preventionTips":["Ensure source files exist and are readable by the peer process","Check disk space before packaging large trees","Don't mutate the source tree during packaging"],"tags":["chaincode","tar","packaging","hyperledger-fabric"],"backgroundTag":"tar-packaging-failure","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"}