{"record":{"id":"0087e7a2e0b0c005","repo":"hyperledger/fabric","slug":"failed-to-write-chaincode-package-to-s","errorCode":null,"errorMessage":"failed to write chaincode package to %s","messagePattern":"failed to write chaincode package to (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/lifecycle/chaincode/getinstalledpackage.go","lineNumber":166,"sourceCode":"\nfunc (i *InstalledPackageGetter) writePackage(proposalResponse *pb.ProposalResponse) error {\n\tresult := &lb.GetInstalledChaincodePackageResult{}\n\terr := proto.Unmarshal(proposalResponse.Response.Payload, result)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"failed to unmarshal proposal response's response payload\")\n\t}\n\n\toutputFile := filepath.Join(i.Input.OutputDirectory, i.Input.PackageID+\".tar.gz\")\n\n\tdir, name := filepath.Split(outputFile)\n\t// translate dir into absolute path\n\tif dir, err = filepath.Abs(dir); err != nil {\n\t\treturn err\n\t}\n\n\terr = i.Writer.WriteFile(dir, name, result.ChaincodeInstallPackage)\n\tif err != nil {\n\t\terr = errors.Wrapf(err, \"failed to write chaincode package to %s\", outputFile)\n\t\tlogger.Error(err.Error())\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\nfunc (i *InstalledPackageGetter) createProposal() (*pb.Proposal, error) {\n\targs := &lb.GetInstalledChaincodePackageArgs{\n\t\tPackageId: i.Input.PackageID,\n\t}\n\n\targsBytes, err := proto.Marshal(args)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to marshal args\")\n\t}\n\n\tccInput := &pb.ChaincodeInput{","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/lifecycle/chaincode/getinstalledpackage.go#L148-L184","documentation":"After successfully unmarshaling the package result, writePackage() failed writing the chaincode package tar.gz to disk via i.Writer.WriteFile, wrapping the OS error with the target output path. Usually a filesystem problem: bad directory, permissions, or disk full.","triggerScenarios":"Writer.WriteFile(dir, name, result.ChaincodeInstallPackage) returns an error while storing <OutputDirectory>/<PackageID>.tar.gz — directory doesn't exist, is unwritable, or the disk is full.","commonSituations":"--output-directory points to a nonexistent or read-only path; running as a user lacking write permission; output dir on a full or read-only mounted volume; PackageID containing characters that make an invalid filename.","solutions":["Create the output directory first (mkdir -p) or pass an existing directory via --output-directory.","Check write permissions on the directory for the current user.","Verify free disk space on the target volume.","Confirm the target path is not a read-only mount."],"exampleFix":"// before\npeer lifecycle chaincode getinstalledpackage --package-id cc_1:abc --output-dir /nonexistent/dir\n// after\nmkdir -p /opt/packages\npeer lifecycle chaincode getinstalledpackage --package-id cc_1:abc --output-dir /opt/packages","handlingStrategy":"validation","validationCode":"outDir := i.Input.OutputDirectory\nif st, err := os.Stat(outDir); err != nil || !st.IsDir() {\n    return fmt.Errorf(\"output directory %s not usable\", outDir)\n}\nif f, err := os.OpenFile(filepath.Join(outDir, \".write-test\"), os.O_CREATE|os.O_WRONLY, 0600); err == nil { f.Close() } else { return err }","typeGuard":null,"tryCatchPattern":"if err := getter.Get(); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) {\n        // fix directory/permissions and retry\n    }\n    return err\n}","preventionTips":["mkdir -p the output directory before running","Check disk space and mount ro/rw status","Run as a user with write access","Sanitize PackageID-derived filenames"],"tags":["fabric","filesystem","io","permissions"],"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-08T10:18:20.063Z"}