{"record":{"id":"c80552a49853e481","repo":"hashicorp/packer","slug":"could-not-write-final-plugin-binary-file-w","errorCode":null,"errorMessage":"could not write final plugin binary file: %w","messagePattern":"could not write final plugin binary file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packer/plugin-getter/plugins.go","lineNumber":919,"sourceCode":"\t\t\t\t\t\t}\n\t\t\t\t\t\treturn nil, errs\n\t\t\t\t\t}\n\n\t\t\t\t\t// create directories if need be\n\t\t\t\t\tif err := os.MkdirAll(outputFolder, 0755); err != nil {\n\t\t\t\t\t\terr := fmt.Errorf(\"could not create plugin folder %q: %w\", outputFolder, err)\n\t\t\t\t\t\terrs = multierror.Append(errs, err)\n\t\t\t\t\t\tlog.Printf(\"[TRACE] %s\", err.Error())\n\t\t\t\t\t\treturn nil, errs\n\t\t\t\t\t}\n\t\t\t\t\toutputFile, err := os.OpenFile(outputFileName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\terr = fmt.Errorf(\"could not create final plugin binary file: %w\", err)\n\t\t\t\t\t\terrs = multierror.Append(errs, err)\n\t\t\t\t\t\treturn nil, errs\n\t\t\t\t\t}\n\t\t\t\t\tif _, err := outputFile.Write(outputFileData.Bytes()); err != nil {\n\t\t\t\t\t\terr = fmt.Errorf(\"could not write final plugin binary file: %w\", err)\n\t\t\t\t\t\terrs = multierror.Append(errs, err)\n\t\t\t\t\t\treturn nil, errs\n\t\t\t\t\t}\n\t\t\t\t\toutputFile.Close()\n\n\t\t\t\t\tcs, err = checksum.Checksummer.Sum(&outputFileData)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\terr := fmt.Errorf(\"failed to checksum binary file: %s\", err)\n\t\t\t\t\t\terrs = multierror.Append(errs, err)\n\t\t\t\t\t\tlog.Printf(\"[WARNING] %v, ignoring\", err)\n\t\t\t\t\t}\n\t\t\t\t\tif err := os.WriteFile(outputFileName+checksum.Checksummer.FileExt(), []byte(hex.EncodeToString(cs)), 0644); err != nil {\n\t\t\t\t\t\terr := fmt.Errorf(\"failed to write local binary checksum file: %s\", err)\n\t\t\t\t\t\terrs = multierror.Append(errs, err)\n\t\t\t\t\t\tlog.Printf(\"[WARNING] %v, ignoring\", err)\n\t\t\t\t\t\tos.Remove(outputFileName)\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}","sourceCodeStart":901,"sourceCodeEnd":937,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/packer/plugin-getter/plugins.go#L901-L937","documentation":"InstallLatest has downloaded a plugin binary into a buffer and opened the final destination file in the plugin directory, but writing the buffered bytes to that file failed. The getter treats this as fatal for that plugin requirement and aborts the install. It wraps the underlying OS error, which is the real diagnostic.","triggerScenarios":"outputFile.Write() returns an error during InstallLatest — typically disk full (ENOSPC), permission denied on the newly created file, or I/O error on the target filesystem.","commonSituations":"Disk quota exhausted in ~/.packer.d/plugins; read-only mount or noexec/immutable file attributes; antivirus or another process locking the freshly created binary; running packer as a user without write access to PACKER_PLUGIN_PATH.","solutions":["Check free disk space on the partition holding the Packer plugins directory (df -h ~/.packer.d) and free space if needed","Inspect the wrapped cause (%w) in the full error for ENOSPC/EPERM/EACCES and fix that specific condition","Remove the partial plugin file and directory, then re-run `packer init`","Ensure the directory permissions allow writes for the user running packer; avoid running with a mismatched user (sudo)","Set PACKER_PLUGIN_PATH to a writable location if the default path is restricted"],"exampleFix":"// before (running as root then as user leaves mixed-permission files)\nsudo packer init .\n// after\nrm -rf ~/.packer.d/plugins/github.com/broken-plugin\npacker init .","handlingStrategy":"validation","validationCode":"import \"os\"\n// before `packer init` in CI:\ninfo, err := os.Stat(pluginDir)\nif err != nil || !info.IsDir() {\n    return fmt.Errorf(\"plugin dir %s missing or not writable: %w\", pluginDir, err)\n}\nif err := checkFreeSpace(pluginDir, 500*1024*1024); err != nil { // require 500MB\n    return err\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Monitor disk space on the volume hosting ~/.packer.d before CI runs","Run packer as a consistent (non-root) user so plugin dir permissions stay uniform","Keep PACKER_PLUGIN_PATH on a normal exec-enabled, writable filesystem","Clean partial plugin files after failed installs"],"tags":["plugin-install","filesystem","io-error","packer"],"backgroundTag":"disk-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"}