{"record":{"id":"0c896a1b4440481e","repo":"hashicorp/packer","slug":"failed-to-copy-s-data-to-archive-s","errorCode":null,"errorMessage":"Failed to copy %s data to archive: %s","messagePattern":"Failed to copy (.+?) data to archive: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/compress/post-processor.go","lineNumber":406,"sourceCode":"\t\tfi, err := file.Stat()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Unable to get fileinfo for %s: %s\", path, err)\n\t\t}\n\n\t\theader, err := tar.FileInfoHeader(fi, path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to create tar header for %s: %s\", path, err)\n\t\t}\n\n\t\t// workaround for archive format on go >=1.10\n\t\tsetHeaderFormat(header)\n\n\t\tif err := archive.WriteHeader(header); err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to write tar header for %s: %s\", path, err)\n\t\t}\n\n\t\tif _, err := io.Copy(archive, file); err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to copy %s data to archive: %s\", path, err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc createZipArchive(files []string, output io.WriteCloser) error {\n\tarchive := zip.NewWriter(output)\n\tdefer archive.Close()\n\n\tfor _, path := range files {\n\t\tpath = filepath.ToSlash(path)\n\n\t\tsource, err := os.Open(path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Unable to read file %s: %s\", path, err)\n\t\t}\n\t\tdefer source.Close()\n","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/compress/post-processor.go#L388-L424","documentation":"After successfully writing the tar header, createTarArchive streams the file body into the archive with io.Copy(archive, file). If copying bytes to the tar (and its compression) writer fails, the post-processor returns this error naming the file path and cause. The archive is incomplete and the build fails.","triggerScenarios":"io.Copy from the opened source file to archive.Writer returns an error — usually the output stream broke (disk full, pipe closed, compression writer error) or a read error occurred on the source file.","commonSituations":"Output volume fills while writing a large archive; NFS/network storage drops mid-write; source file truncated or unreadable after os.Open succeeded (e.g. file changed on disk); gzip/zstd writer hit an internal error that surfaces here.","solutions":["Free disk space on the output path and verify the storage target is writable and reachable.","Re-run the build once the underlying storage issue is fixed.","Read the wrapped cause in the message to identify whether it's a read or write failure.","Keep the compress post-processor's output on local/reliable storage rather than flaky network mounts."],"exampleFix":"// before: output to a small tmpfs\n{\"type\": \"compress\", \"output\": \"/tmp/artifact.tar.gz\"} // tmpfs too small for 10GB image\n// after\n{\"type\": \"compress\", \"output\": \"/var/artifacts/artifact.tar.gz\"}","handlingStrategy":"validation","validationCode":"// preflight disk space before compressing\nconst stat = fs.statfsSync(outDir)\nif (stat.bavail * stat.bsize) < requiredBytes throw new Error('insufficient space for archive')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure free disk space exceeds the uncompressed artifact size.","Avoid compressing onto tmpfs or small CI volumes.","Don't mutate the output directory while packer runs.","Retry only after fixing storage, not blindly."],"tags":["archive","tar","io","post-processor"],"backgroundTag":"archive-write-failed","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}