{"record":{"id":"5faf75d859b1ef0a","repo":"hashicorp/packer","slug":"unable-to-read-file-s-s","errorCode":null,"errorMessage":"Unable to read file %s: %s","messagePattern":"Unable to read file (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/compress/post-processor.go","lineNumber":384,"sourceCode":"}\n\nfunc makePgzipWriter(output io.WriteCloser, compressionLevel int) (io.WriteCloser, error) {\n\tgzipWriter, err := pgzip.NewWriterLevel(output, compressionLevel)\n\tif err != nil {\n\t\treturn nil, ErrInvalidCompressionLevel\n\t}\n\t_ = gzipWriter.SetConcurrency(500000, runtime.GOMAXPROCS(-1))\n\treturn gzipWriter, nil\n}\n\nfunc createTarArchive(files []string, output io.WriteCloser) error {\n\tarchive := tar.NewWriter(output)\n\tdefer archive.Close()\n\n\tfor _, path := range files {\n\t\tfile, 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 file.Close()\n\n\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)","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/compress/post-processor.go#L366-L402","documentation":"createTarArchive could not open one of the artifact files for reading while building the tar stream in Packer's compress post-processor. os.Open(path) failed for a specific path, so tar creation stops and PostProcess wraps the failure as 'Error creating tar'.","triggerScenarios":"createTarArchive iterates artifact.Files() and os.Open returns an error for one path: file deleted after the artifact was produced, permission denied, or the path is a dangling symlink/directory.","commonSituations":"Artifact files removed between builder completion and the compress post-processor; running Packer without read permission on generated disk images; checksum/sidecar files referenced by the artifact no longer present.","solutions":["Check the failing path from the error: verify it exists and is readable (ls -l)","Fix permissions or restore the missing file before the compress step","Reorder post-processors so nothing deletes artifact files before compress runs","Re-run the build from the builder step to regenerate the artifact files"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// pre-flight: every artifact path must exist and be a readable regular file\nfor _, p := range artifact.Files() {\n    fi, err := os.Stat(p)\n    if err != nil { return fmt.Errorf(\"cannot tar %s: %w\", p, err) }\n    if !fi.Mode().IsRegular() { return fmt.Errorf(\"skipping non-regular file %s\", p) }\n    if file, err := os.Open(p); err != nil { return err } else { file.Close() }\n}","typeGuard":null,"tryCatchPattern":"// Go: unwrap to find the failing path\nif err != nil && strings.Contains(err.Error(), \"Error creating tar\") {\n    if strings.Contains(err.Error(), \"Unable to read file\") {\n        // log path from inner message; restore permissions/file and retry\n    }\n    return err\n}","preventionTips":["Never delete artifact files between build and post-process stages","Grant the Packer user read access to all artifact paths","Validate artifact file lists before the compress step","Run artifact-mutating post-processors after compression, not before"],"tags":["packer","post-processor","tar","filesystem"],"backgroundTag":"file-open-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"}