{"record":{"id":"3b81e06dc8c651d8","repo":"hashicorp/packer","slug":"error-creating-tar-s","errorCode":null,"errorMessage":"Error creating tar: %s","messagePattern":"Error creating tar: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/compress/post-processor.go","lineNumber":215,"sourceCode":"\t\t\t\tfmt.Errorf(errTmpl, p.config.Algorithm, err)\n\t\t}\n\t\tdefer output.Close()\n\tdefault:\n\t\toutput = outputFile\n\t}\n\n\tcompression := p.config.Algorithm\n\tif compression == \"\" {\n\t\tcompression = \"no compression\"\n\t}\n\n\t// Build an archive, if we're supposed to do that.\n\tswitch p.config.Archive {\n\tcase \"tar\":\n\t\tui.Say(fmt.Sprintf(\"Tarring %s with %s\", target, compression))\n\t\terr = createTarArchive(artifact.Files(), output)\n\t\tif err != nil {\n\t\t\treturn nil, false, false, fmt.Errorf(\"Error creating tar: %s\", err)\n\t\t}\n\tcase \"zip\":\n\t\tui.Say(fmt.Sprintf(\"Zipping %s\", target))\n\t\terr = createZipArchive(artifact.Files(), output)\n\t\tif err != nil {\n\t\t\treturn nil, false, false, fmt.Errorf(\"Error creating zip: %s\", err)\n\t\t}\n\tdefault:\n\t\t// Filename indicates no tarball (just compress) so we'll do an io.Copy\n\t\t// into our compressor.\n\t\tif len(artifact.Files()) != 1 {\n\t\t\treturn nil, false, false, fmt.Errorf(\n\t\t\t\t\"Can only have 1 input file when not using tar/zip. Found %d \"+\n\t\t\t\t\t\"files: %v\", len(artifact.Files()), artifact.Files())\n\t\t}\n\t\tarchiveFile := artifact.Files()[0]\n\t\tui.Say(fmt.Sprintf(\"Archiving %s with %s\", archiveFile, compression))\n","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/compress/post-processor.go#L197-L233","documentation":"The tar archiving step inside Packer's compress post-processor failed. createTarArchive writes every artifact file into a tar stream on top of the compression writer; any per-file or stream error is wrapped as 'Error creating tar'. This aborts the build and invalidates the partially written output file.","triggerScenarios":"PostProcess with archive set to \"tar\" (or filename ending in .tar*) and createTarArchive returning an error: an artifact file cannot be opened/stated, a tar header cannot be built, or a WriteHeader/Write to the tar stream fails.","commonSituations":"Artifact files vanished between build and post-process; disk full while writing the archive; permission problems on files produced by the builder; a file removed by a prior post-processor.","solutions":["Read the wrapped inner error to identify the failing file or stream condition","Verify all artifact files exist and are readable before the compress step","Check free disk space in the output_directory / output path","Re-run after cleaning stale output files that may conflict"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-flight: ensure all artifact files exist and are readable\nfor _, f := range artifact.Files() {\n    fi, err := os.Stat(f)\n    if err != nil { return fmt.Errorf(\"artifact file missing: %s: %w\", f, err) }\n    if !fi.Mode().IsRegular() { return fmt.Errorf(\"not a regular file: %s\", f) }\n}","typeGuard":null,"tryCatchPattern":"// Go: inspect the returned wrapped error\nartifact, _, _, err := pp.PostProcess(ctx, ui, artifact)\nif err != nil {\n    if strings.Contains(err.Error(), \"Error creating tar\") {\n        // log inner cause, free disk space, retry\n    }\n    return err\n}","preventionTips":["Check free disk space before large archive builds","Don't delete artifact files between builder and post-processor steps","Run Packer as a user with read access to all build outputs","Handle the wrapped inner error, not just the outer message"],"tags":["packer","post-processor","tar","archive"],"backgroundTag":"archive-creation-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"}