{"record":{"id":"d4e50ed1e5e41c1e","repo":"hashicorp/terraform","slug":"failed-to-read-stacks-plugin-stored-path-file-w","errorCode":null,"errorMessage":"failed to read stacks plugin stored path file: %w","messagePattern":"failed to read stacks plugin stored path file: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/stacks.go","lineNumber":394,"sourceCode":"func (c *StacksCommand) initPackagesCache() (string, error) {\n\tvar pluginPath string\n\tdefaultPluginPath := path.Join(c.CLIConfigDir, StacksPluginDataDir)\n\tcacheStorePath := path.Join(c.WorkingDir.DataDir(), \".stackspluginpath\")\n\n\tif _, err := os.Stat(cacheStorePath); err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\tlog.Printf(\"[TRACE] No stacksplugin cache path store at '%s`, using default '%s'\", cacheStorePath, defaultPluginPath)\n\t\t\t// Use the default plugin cache path if the file does not exist\n\t\t\tpluginPath = defaultPluginPath\n\t\t} else {\n\t\t\tlog.Printf(\"[TRACE] Failed to check the stacksplugin cache path store at '%s', using default '%s'\", cacheStorePath, defaultPluginPath)\n\t\t\t// Use the default plugin cache path if there was an error checking the file\n\t\t\tpluginPath = defaultPluginPath\n\t\t}\n\t} else {\n\t\tdata, err := os.ReadFile(cacheStorePath)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to read stacks plugin stored path file: %w\", err)\n\t\t}\n\t\tpluginPath = string(data)\n\t}\n\n\tif info, err := os.Stat(pluginPath); err != nil || !info.IsDir() {\n\t\tlog.Printf(\"[TRACE] initialized stacksplugin cache directory at %q\", pluginPath)\n\t\terr = os.MkdirAll(pluginPath, 0755)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to initialize stacksplugin cache directory: %w\", err)\n\t\t}\n\t} else {\n\t\tlog.Printf(\"[TRACE] stacksplugin cache directory found at %q\", pluginPath)\n\t}\n\n\treturn pluginPath, nil\n}\n\nfunc (c *StacksCommand) storeStacksPluginPath(pluginCachePath string) error {","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/stacks.go#L376-L412","documentation":"Wrapped error from StacksCommand.initPackagesCache when os.ReadFile(cacheStorePath) fails. cacheStorePath is <data-dir>/.stackspluginpath, a small file recording where the stacks plugin cache lives. It is only read when os.Stat reported the file exists, so a read failure here is unusual — typically a race (file deleted between stat and read) or a permission issue.","triggerScenarios":"Running a stacks command when .stackspluginpath exists (stat succeeded) but os.ReadFile then fails — file removed concurrently, permission denied between stat and read, or the path is a directory/special file.","commonSituations":"Concurrent 'terraform init' / cleanup deleting .stackspluginpath mid-run; permission/ownership change on the data dir; the file got replaced by a directory of the same name; exotic filesystem (NFS) consistency lag.","solutions":["Delete .stackspluginpath and re-run; the command will fall back to the default cache path and recreate it.","Ensure the data directory (.terraform) is writable and not modified concurrently.","Avoid running multiple stacks/init commands against the same working dir simultaneously.","Check file permissions/ownership of the data dir."],"exampleFix":"// before\n$ terraform stacks init\nfailed to read stacks plugin stored path file: ...\n// after\n$ rm -f .terraform/.stackspluginpath\n$ terraform stacks init","handlingStrategy":"validation","validationCode":"// Pre-flight: ensure .stackspluginpath is a readable regular file (or absent) before stacks commands\npackage main\n\nfunc preflightStacksPluginPath(dataDir string) error {\n\tp := filepath.Join(dataDir, \".stackspluginpath\")\n\tinfo, err := os.Stat(p)\n\tif err != nil { return nil /* absent is fine */ }\n\tif info.IsDir() { return fmt.Errorf(\"%s is a directory, expected a file\", p) }\n\tif info.Size() == 0 { return fmt.Errorf(\"%s is empty; delete it to use the default cache path\", p) }\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid running multiple stacks/init commands against the same working dir concurrently.","Delete a stale .stackspluginpath rather than editing it by hand.","Keep the .terraform data dir writable and stable."],"tags":["stacks","plugin-cache","filesystem","race"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}