{"record":{"id":"2cae54065717ed66","repo":"hyperledger/fabric","slug":"failed-to-create-chaincode-package-s","errorCode":null,"errorMessage":"failed to create chaincode package: %s","messagePattern":"failed to create chaincode package: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/platforms/java/platform.go","lineNumber":112,"sourceCode":"\t\tlogger.Error(\"ChaincodeSpec's path cannot be empty\")\n\t\treturn nil, errors.New(\"ChaincodeSpec's path cannot be empty\")\n\t}\n\n\t// trim trailing slash if it exists\n\tif path[len(path)-1] == '/' {\n\t\tpath = path[:len(path)-1]\n\t}\n\n\tbuf := &bytes.Buffer{}\n\tgw := gzip.NewWriter(buf)\n\ttw := tar.NewWriter(gw)\n\n\texcludedDirs := []string{\"target\", \"build\", \"out\"}\n\texcludedFileTypes := map[string]bool{\".class\": true}\n\terr := util.WriteFolderToTarPackage(tw, path, excludedDirs, nil, excludedFileTypes)\n\tif err != nil {\n\t\tlogger.Errorf(\"Error writing java project to tar package %s\", err)\n\t\treturn nil, fmt.Errorf(\"failed to create chaincode package: %s\", err)\n\t}\n\n\ttw.Close()\n\tgw.Close()\n\n\treturn buf.Bytes(), nil\n}\n\nfunc (p *Platform) GenerateDockerfile() (string, error) {\n\tvar buf []string\n\n\tbuf = append(buf, \"FROM \"+util.GetDockerImageFromConfig(\"chaincode.java.runtime\"))\n\tbuf = append(buf, \"ADD binpackage.tar /root/chaincode-java/chaincode\")\n\n\tdockerFileContents := strings.Join(buf, \"\\n\")\n\n\treturn dockerFileContents, nil\n}","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/platforms/java/platform.go#L94-L130","documentation":"GetDeploymentPayload walks the project folder and writes files into the tar via util.WriteFolderToTarPackage; if that walk/write fails (unreadable files, I/O errors, excluded-file handling issues), the error is wrapped and surfaced as a package-creation failure.","triggerScenarios":"WriteFolderToTarPackage returns an error while traversing the project directory — unreadable file, I/O failure writing to the tar/zip writer, or a wrapped error from walking excluded dirs.","commonSituations":"The chaincode source directory is unreadable (permissions) or was deleted mid-package; disk full while building the in-memory buffer; the path points to a file rather than a directory; filesystem errors in a containerized build.","solutions":["Check read permissions on the chaincode source directory and its files","Verify the path points to an existing directory (the Java project root)","Check available disk/memory since the package is built in a buffer","Re-run packaging; inspect the wrapped cause in the error message for the true failure"],"exampleFix":"// before\npath := \"/opt/chaincode/java/mycc\" // directory deleted by CI cleanup\npayload, err := platform.GetDeploymentPayload(path)\n// after\npath := \"/opt/chaincode/java/mycc\" // ensure it exists and is readable\nif _, err := os.Stat(path); err != nil { return nil, err }\npayload, err := platform.GetDeploymentPayload(path)","handlingStrategy":"try-catch","validationCode":"if fi, err := os.Stat(path); err != nil || !fi.IsDir() { return errors.New(\"path must be an existing readable directory\") }","typeGuard":null,"tryCatchPattern":"payload, err := platform.GetDeploymentPayload(path)\nif err != nil && strings.Contains(err.Error(), \"failed to create chaincode package\") {\n    // inspect cause; fix fs issue then retry packaging\n}","preventionTips":["Check read permissions on source tree before packaging","Avoid mutating the source directory during packaging","Monitor disk space on build hosts"],"tags":["chaincode","java","packaging","io"],"backgroundTag":"package-write-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"}