{"record":{"id":"25be41caa65e46f5","repo":"hyperledger/fabric","slug":"error-writing-chaincode-package-to-s","errorCode":null,"errorMessage":"error writing chaincode package to %s","messagePattern":"error writing chaincode package to (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/lifecycle/chaincode/package.go","lineNumber":148,"sourceCode":"\terr := p.Input.Validate()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tpkgTarGzBytes, err := p.getTarGzBytes()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tdir, name := filepath.Split(p.Input.OutputFile)\n\t// if p.Input.OutputFile is only file name, dir becomes an empty string that creates problem\n\t// while invoking 'WriteFile' function below. So, irrespective, translate dir into absolute path\n\tif dir, err = filepath.Abs(dir); err != nil {\n\t\treturn err\n\t}\n\terr = p.Writer.WriteFile(dir, name, pkgTarGzBytes)\n\tif err != nil {\n\t\terr = errors.Wrapf(err, \"error writing chaincode package to %s\", p.Input.OutputFile)\n\t\tlogger.Error(err.Error())\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\nfunc (p *Packager) getTarGzBytes() ([]byte, error) {\n\tpayload := bytes.NewBuffer(nil)\n\tgw := gzip.NewWriter(payload)\n\ttw := tar.NewWriter(gw)\n\n\tnormalizedPath, err := p.PlatformRegistry.NormalizePath(strings.ToUpper(p.Input.Type), p.Input.Path)\n\tif err != nil {\n\t\treturn nil, errors.WithMessage(err, \"failed to normalize chaincode path\")\n\t}\n\tmetadataBytes, err := toJSON(normalizedPath, p.Input.Type, p.Input.Label)\n\tif err != nil {","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/lifecycle/chaincode/package.go#L130-L166","documentation":"After getTarGzBytes builds the package, Package writes the tar.gz bytes to p.Input.OutputFile via the injected Writer.WriteFile. If that filesystem write fails, the error is wrapped with 'error writing chaincode package to <output file>'. It is a filesystem-level failure, not a chaincode or network issue.","triggerScenarios":"Output path in a non-existent directory; no write permission on the target directory; disk full; output path is a directory rather than a file.","commonSituations":"CI writing to a read-only volume; containerized peer running as non-root writing to /; NFS mounts with permission issues; typos in the output path creating a deep nonexistent directory.","solutions":["Create the output directory first (mkdir -p) or point OutputFile at an existing writable directory.","Check permissions/ownership of the target directory (ls -ld) and run as a user with write access.","Verify free disk space (df -h) and that the target is not a directory.","Read the wrapped inner error after the colon — it states the exact OS reason (permission denied, no such file, etc.)."],"exampleFix":"// before: parent dir may not exist\npeer lifecycle chaincode package /output/basic.tar.gz --path . --lang golang --label basic_1.0\n// after (ensure dir exists and is writable)\nmkdir -p /output\npeer lifecycle chaincode package /output/basic.tar.gz --path . --lang golang --label basic_1.0","handlingStrategy":"try-catch","validationCode":"#!/bin/bash\nOUT_DIR=$(dirname \"$OUT\")\nmkdir -p \"$OUT_DIR\"\n[ -w \"$OUT_DIR\" ] || { echo \"not writable: $OUT_DIR\"; exit 1; }\n[ ! -d \"$OUT\" ] || { echo \"$OUT is a directory\"; exit 1; }\ndf -h \"$OUT_DIR\" | awk 'NR==2 {exit ($5+0 > 95 ? 1 : 0)}' || { echo \"low disk space\"; exit 1; }","typeGuard":null,"tryCatchPattern":"if ! out=$(peer lifecycle chaincode package \"$OUT\" ... 2>&1); then\n  case \"$out\" in\n    *\"error writing chaincode package to\"*)\n      echo \"Filesystem write failed: $out\"\n      echo \"Check dir exists, permissions, disk space\"; exit 3 ;;\n    *) echo \"$out\"; exit 1 ;;\n  esac\nfi","preventionTips":["mkdir -p the output directory before packaging.","Run the CLI as a user with write access to the target dir.","Monitor disk space in CI runners.","Never point the output file at an existing directory."],"tags":["hyperledger-fabric","filesystem","io-error","cli"],"backgroundTag":"file-write-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}