{"record":{"id":"ee352fcc088d7cb7","repo":"hyperledger/fabric","slug":"error-writing-chaincode-package-contents-s","errorCode":null,"errorMessage":"Error writing Chaincode package contents: %s","messagePattern":"Error writing Chaincode package contents: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/platforms/node/platform.go","lineNumber":151,"sourceCode":"\tpayload := bytes.NewBuffer(nil)\n\tgw := gzip.NewWriter(payload)\n\ttw := tar.NewWriter(gw)\n\n\tfolder := path\n\tif folder == \"\" {\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 folder[len(folder)-1] == '/' {\n\t\tfolder = folder[:len(folder)-1]\n\t}\n\n\tlogger.Debugf(\"Packaging node.js project from path %s\", folder)\n\n\tif err = util.WriteFolderToTarPackage(tw, folder, []string{\"node_modules\"}, nil, nil); err != nil {\n\t\tlogger.Errorf(\"Error writing folder to tar package %s\", err)\n\t\treturn nil, fmt.Errorf(\"Error writing Chaincode package contents: %s\", err)\n\t}\n\n\t// Write the tar file out\n\tif err := tw.Close(); err != nil {\n\t\treturn nil, fmt.Errorf(\"Error writing Chaincode package contents: %s\", err)\n\t}\n\n\ttw.Close()\n\tgw.Close()\n\n\treturn payload.Bytes(), nil\n}\n\nfunc (p *Platform) GenerateDockerfile() (string, error) {\n\tvar buf []string\n\n\tbuf = append(buf, \"FROM \"+util.GetDockerImageFromConfig(\"chaincode.node.runtime\"))\n\tbuf = append(buf, \"ADD binpackage.tar /usr/local/src\")","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/platforms/node/platform.go#L133-L169","documentation":"While packaging the node.js project, util.WriteFolderToTarPackage failed to write the source folder's contents into the tar writer. The platform logs the underlying error and wraps it as 'Error writing Chaincode package contents'. This is a packaging/I/O failure, not a code validation failure.","triggerScenarios":"GetDeploymentPayload called with a folder whose contents cannot be walked or written to the tar stream — missing source directory, unreadable files, or util.WriteFolderToTarPackage returning an error (it excludes 'node_modules').","commonSituations":"Chaincode path points to a nonexistent or misspelled directory, permission errors on source files, disk or stream failures during tar/gzip writes, or packaging from a path where files were deleted mid-build.","solutions":["Check the wrapped underlying error in the message/ logs; fix the root cause it reports.","Verify the ChaincodeSpec path exists and is readable (ls <path>).","Re-run packaging after restoring missing/unreadable source files.","Exclude problematic files (node_modules is already skipped) and retry the package command."],"exampleFix":"// before\npeer chaincode package -p ./nonexistent-dir -n cc -l node\n// after\npeer chaincode package -p ./correct-chaincode-dir -n cc -l node","handlingStrategy":"try-catch","validationCode":"const fs = require('fs');\nif (!fs.existsSync(chaincodePath) || !fs.statSync(chaincodePath).isDirectory()) {\n  throw new Error(`Chaincode path ${chaincodePath} does not exist or is not a directory`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  payload = getDeploymentPayload(spec);\n} catch (err) {\n  if (/Error writing Chaincode package contents/.test(err.message)) {\n    // check source path exists/readable, fix permissions, then retry once\n  }\n  throw err;\n}","preventionTips":["Verify the chaincode directory exists and is readable before packaging","Check disk space and permissions in the build environment","Avoid deleting files while packaging is in flight","Read the wrapped underlying error for the precise root cause"],"tags":["chaincode","packaging","io","filesystem"],"backgroundTag":"packaging-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"}