{"record":{"id":"506814f267a300e2","repo":"hashicorp/packer","slug":"could-not-create-plugin-folder-q-w","errorCode":null,"errorMessage":"could not create plugin folder %q: %w","messagePattern":"could not create plugin folder %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packer/plugin-getter/plugins.go","lineNumber":907,"sourceCode":"\t\t\t\t\tif _, err := tmpOutputFile.Write(outputFileData.Bytes()); err != nil {\n\t\t\t\t\t\terr := fmt.Errorf(\"extract 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\ttmpOutputFile.Close()\n\n\t\t\t\t\tif err := checkVersion(tmpBinFileName, pr.Identifier.String(), version); err != nil {\n\t\t\t\t\t\terrs = multierror.Append(errs, err)\n\t\t\t\t\t\tvar continuableError *ContinuableInstallError\n\t\t\t\t\t\tif errors.As(err, &continuableError) {\n\t\t\t\t\t\t\tcontinue\n\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)","sourceCodeStart":889,"sourceCodeEnd":925,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/packer/plugin-getter/plugins.go#L889-L925","documentation":"Once the plugin binary passes checkVersion, InstallLatest creates the final output directory (the plugin's install folder under the Packer plugin directory) with os.MkdirAll(outputFolder, 0755). If that fails, the error is wrapped as \"could not create plugin folder %q: %w\", logged at TRACE level, and returned via the multierror.","triggerScenarios":"InstallLatest when os.MkdirAll(outputFolder, 0755) fails — parent path unwritable, a file exists where a directory is needed, or invalid path characters.","commonSituations":"PACKER_PLUGIN_PATH or the default ~/.packer.d/plugins tree owned by another user or read-only; a regular file occupying a path segment of outputFolder; running Packer as a different user than the one who owns the plugin dir (e.g. after sudo installs); path too long or illegal characters from an unusual plugin name/version.","solutions":["Check permissions/ownership on the plugin directory (ls -ld ~/.packer.d ~/.packer.d/plugins) and chown/chmod so the running user can write.","Ensure no regular file exists at any segment of outputFolder; remove or rename it.","Run Packer as the user that owns the plugin directory instead of mixing sudo/non-sudo installs.","Set PACKER_PLUGIN_PATH to a writable location and retry.","Fix invalid path characters or shorten the path if the plugin name/version produces one."],"exampleFix":"// before: plugin dir owned by root after a sudo install\nsudo chown -R $(whoami) ~/.packer.d\n// after: install succeeds\npacker plugins install github.com/hashicorp/...","handlingStrategy":"validation","validationCode":"// before install: verify the plugin output location is writable\nbase := os.Getenv(\"PACKER_PLUGIN_PATH\")\nif base == \"\" {\n    home, _ := os.UserHomeDir()\n    base = filepath.Join(home, \".packer.d\", \"plugins\")\n}\nif err := os.MkdirAll(base, 0o755); err != nil {\n    return fmt.Errorf(\"plugin dir not writable: %w\", err)\n}\nprobe := filepath.Join(base, \".write-test\")\nif err := os.WriteFile(probe, nil, 0o644); err != nil {\n    return fmt.Errorf(\"cannot write to plugin dir: %w\", err)\n}\nos.Remove(probe)","typeGuard":null,"tryCatchPattern":"err := getter.InstallLatest(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"could not create plugin folder\") {\n    // point installs at a writable location and retry\n    os.Setenv(\"PACKER_PLUGIN_PATH\", filepath.Join(os.TempDir(), \"packer-plugins\"))\n    return getter.InstallLatest(ctx, req)\n}","preventionTips":["Never mix sudo and non-sudo Packer plugin installs; keep ~/.packer.d owned by the running user.","Set PACKER_PLUGIN_PATH explicitly in CI/containers to a writable volume.","Check that no file occupies a directory path in the plugin tree.","Mount persistent, read-write volumes for plugin caches.","Fix ownership after copying plugin dirs between users/machines (chown -R)."],"tags":["go","plugin-install","filesystem","mkdir","permissions"],"backgroundTag":"mkdir-permission-denied","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"}