{"record":{"id":"eaa01c3855199ec7","repo":"hyperledger/fabric","slug":"failed-to-create-tar-for-chaincode","errorCode":null,"errorMessage":"failed to create tar for chaincode","messagePattern":"failed to create tar for chaincode","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/platforms/golang/platform.go","lineNumber":184,"sourceCode":"\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\")\n\n\treturn strings.Join(buf, \"\\n\"), nil\n}\n\nconst (\n\tstaticLDFlagsOpts  = \"-ldflags \\\"-linkmode external -extldflags '-static'\\\"\"\n\tdynamicLDFlagsOpts = \"\"\n)\n","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/platforms/golang/platform.go#L166-L202","documentation":"GetDeploymentPayload wraps any error from closing the tar or gzip writer with 'failed to create tar for chaincode'. Close flushes buffered data, so gzip/tar errors (including earlier write failures deferred to Close) surface here.","triggerScenarios":"Calling GetDeploymentPayload when tw.Close() or gw.Close() returns an error, typically from an underlying write failure to the byte buffer or gzip stream corruption.","commonSituations":"Out-of-memory or buffer write failures, gzip writer already in error state from a previous failed write, concurrent misuse of the platform.","solutions":["Inspect errors.Wrapf result for the underlying cause.","Retry GetDeploymentPayload; ensure all prior writes succeeded.","Ensure the source tree is stable and readable during packaging."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if fi, err := os.Stat(path); err != nil || !fi.IsDir() { return errors.New(\"invalid chaincode path\") }","typeGuard":null,"tryCatchPattern":"payload, err := platform.GetDeploymentPayload(path, code)\nif err != nil {\n\tif strings.Contains(err.Error(), \"failed to create tar for chaincode\") {\n\t\t// retry once; otherwise surface wrapped gzip/tar close error\n\t}\n}","preventionTips":["Retry packaging on transient I/O failures","Keep the source tree stable during packaging","Monitor for the wrapped cause in the error chain"],"tags":["chaincode","tar","gzip","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"}