{"record":{"id":"50bd492ee3b99b86","repo":"hashicorp/packer","slug":"unable-to-create-archive-s-s","errorCode":null,"errorMessage":"Unable to create archive %s: %s","messagePattern":"Unable to create archive (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/compress/post-processor.go","lineNumber":149,"sourceCode":"\tgeneratedData[\"BuilderType\"] = p.config.PackerBuilderType\n\tp.config.ctx.Data = generatedData\n\n\ttarget, err := interpolate.Render(p.config.OutputPath, &p.config.ctx)\n\tif err != nil {\n\t\treturn nil, false, false, fmt.Errorf(\"Error interpolating output value: %s\", err)\n\t} else {\n\t\tfmt.Println(target)\n\t}\n\n\tnewArtifact := &Artifact{Path: target}\n\n\tif err = os.MkdirAll(filepath.Dir(target), os.FileMode(0755)); err != nil {\n\t\treturn nil, false, false, fmt.Errorf(\n\t\t\t\"Unable to create dir for archive %s: %s\", target, err)\n\t}\n\toutputFile, err := os.Create(target)\n\tif err != nil {\n\t\treturn nil, false, false, fmt.Errorf(\n\t\t\t\"Unable to create archive %s: %s\", target, err)\n\t}\n\tdefer outputFile.Close()\n\n\t// Setup output interface. If we're using compression, output is a\n\t// compression writer. Otherwise it's just a file.\n\tvar output io.WriteCloser\n\terrTmpl := \"error creating %s writer: %s\"\n\tswitch p.config.Algorithm {\n\tcase \"bgzf\":\n\t\tui.Say(fmt.Sprintf(\"Using bgzf compression with %d cores for %s\",\n\t\t\truntime.GOMAXPROCS(-1), target))\n\t\toutput, err = makeBGZFWriter(outputFile, p.config.CompressionLevel)\n\t\tif err != nil {\n\t\t\treturn nil, false, false, fmt.Errorf(errTmpl, p.config.Algorithm, err)\n\t\t}\n\t\tdefer output.Close()\n\tcase \"bzip2\":","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/compress/post-processor.go#L131-L167","documentation":"After ensuring the directory exists, PostProcess creates the archive file with os.Create. This error means the OS refused to create/truncate the target archive file itself — permission denied, path is a directory, no space, or an unwritable filesystem.","triggerScenarios":"os.Create(target) fails during PostProcess: target exists as a directory, the directory lacks write permission, the filesystem is full or read-only, or the name is invalid for the OS.","commonSituations":"output_path resolving to an existing directory name; disk full after long builds; output dir mounted read-only; filename with characters invalid on the host OS; stale file owned by another user.","solutions":["Check disk space (df -h) and free space if full","Verify the target path is not an existing directory and the filename is valid","Ensure the user running packer can write to the target directory (ls -ld)","Point output_path to a writable location"],"exampleFix":"// before: collides with a directory named artifact.tar.gz\noutput = \"./output/artifact.tar.gz\"\n// after\noutput = \"./output/artifact-{{timestamp}}.tar.gz\"","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(target); err == nil && fi.IsDir() {\n    return fmt.Errorf(\"%s is a directory\", target)\n}\n// also check writability and free space\nif err := unix.Access(filepath.Dir(target), unix.W_OK); err != nil { /* ... */ }","typeGuard":null,"tryCatchPattern":"if err != nil {\n    switch {\n    case errors.Is(err, fs.ErrExist):\n        // target exists as dir or file: choose a unique name\n    case errors.Is(err, fs.ErrPermission):\n        // fall back to another output location\n    default:\n        // check disk full (ENOSPC)\n    }\n}","preventionTips":["Add {{timestamp}} or build name to output_path to avoid collisions","Check disk space before long builds","Verify write permissions on the output directory","Keep output filenames valid for the host OS"],"tags":["filesystem","permissions","disk-full","post-processor"],"backgroundTag":"file-create-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"}