hyperledger/fabric · error
Error writing %s to tar: %s
Error message
Error writing %s to tar: %s
What it means
GetDeploymentPayload builds a tar.gz of the chaincode sources; when util.WriteFileToPackage fails while adding a source file to the tar writer, the file name and underlying error are wrapped in this message. It indicates the package could not be produced.
Source
Thrown at core/chaincode/platforms/golang/platform.go:175
// Create directories so they get sane ownership and permissions
for _, dirname := range fileMap.Directories() {
err := tw.WriteHeader(&tar.Header{
Typeflag: tar.TypeDir,
Name: dirname + "/",
Mode: c_ISDIR | 0o755,
Uid: 500,
Gid: 500,
})
if err != nil {
return nil, err
}
}
for _, file := range fileMap.Sources() {
err = util.WriteFileToPackage(file.Path, file.Name, tw)
if err != nil {
return nil, fmt.Errorf("Error writing %s to tar: %s", file.Name, err)
}
}
err = tw.Close()
if err == nil {
err = gw.Close()
}
if err != nil {
return nil, errors.Wrapf(err, "failed to create tar for chaincode")
}
return payload.Bytes(), nil
}
func (p *Platform) GenerateDockerfile() (string, error) {
var buf []string
buf = append(buf, "FROM "+util.GetDockerImageFromConfig("chaincode.golang.runtime"))
buf = append(buf, "ADD binpackage.tar /usr/local/bin")View on GitHub (pinned to 2736b63f8f)
Solutions
- Check the wrapped %s error to identify the underlying cause (permissions, missing file, I/O).
- Re-run the packaging step; ensure source files exist and are readable by the process.
- Verify the file name does not exceed tar name limits or contain invalid characters.
- Check disk space and that the output buffer/writer is valid.
Defensive patterns
Strategy: try-catch
Validate before calling
for _, f := range files {
if _, err := os.Stat(f); err != nil { return fmt.Errorf("missing source: %s", f) }
} Try / catch
payload, err := platform.GetDeploymentPayload(path, code)
if err != nil {
if strings.Contains(err.Error(), "Error writing") {
// inspect wrapped cause: permissions, missing file, disk space
return fmt.Errorf("packaging failed: %w", err)
}
} Prevention
- Ensure source files exist and are readable by the peer process
- Check disk space before packaging large trees
- Don't mutate the source tree during packaging
When it happens
Trigger: Calling GetDeploymentPayload when a discovered source file cannot be written to the tar, e.g. the file disappeared between walking and writing, permission denied reading it, or the tar/gzip writer is in an error state.
Common situations: Files deleted during packaging, unreadable files due to permissions, disk-full or closed-writer errors during streaming.
Related errors
- illegal file name in payload: %s
- illegal file mode in payload: %s
- failed to create tar for chaincode
- error writing package metadata to tar
- error writing package code bytes to tar
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/9f80c49e25824429.
Report an issue: GitHub.