{"record":{"id":"f046c4e6e0d3a9fc","repo":"JanDeDobbeleer/oh-my-posh","slug":"pulumi-workspace-file-decode-error","errorCode":null,"errorMessage":"pulumi workspace file decode error","messagePattern":"pulumi workspace file decode error","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/segments/pulumi.go","lineNumber":99,"sourceCode":"\t\treturn\n\t}\n\n\tstackNameFile := p.Name + \"-\" + p.workspaceSHA1 + \"-\" + \"workspace.json\"\n\n\thomedir := p.env.Home()\n\n\tworkspaceCacheDir := filepath.Join(homedir, \".pulumi\", \"workspaces\")\n\tif !p.env.HasFolder(workspaceCacheDir) || !p.env.HasFilesInDir(workspaceCacheDir, stackNameFile) {\n\t\treturn\n\t}\n\n\tworkspaceCacheFile := filepath.Join(workspaceCacheDir, stackNameFile)\n\tworkspaceCacheFileContent := p.env.FileContent(workspaceCacheFile)\n\n\tvar pulumiWorkspaceSpec pulumiWorkSpaceFileSpec\n\terr := json.Unmarshal([]byte(workspaceCacheFileContent), &pulumiWorkspaceSpec)\n\tif err != nil {\n\t\tlog.Error(fmt.Errorf(\"pulumi workspace file decode error\"))\n\t\treturn\n\t}\n\n\tlog.Debugf(\"pulumi stack name: %s\", pulumiWorkspaceSpec.Stack)\n\tp.Stack = pulumiWorkspaceSpec.Stack\n}\n\nfunc (p *Pulumi) getProjectName() error {\n\tvar kind, fileName string\n\tfor _, file := range []string{pulumiYAML, pulumiJSON} {\n\t\tif p.env.HasFiles(file) {\n\t\t\tfileName = file\n\t\t\tkind = filepath.Ext(file)[1:]\n\t\t}\n\t}\n\n\tif kind == \"\" {\n\t\treturn fmt.Errorf(\"no pulumi spec file found\")","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/segments/pulumi.go#L81-L117","documentation":"The pulumi segment reads the workspace cache file (~/.pulumi/workspaces/<...>/stack-name.json) and unmarshals it as JSON. If json.Unmarshal fails, the segment logs 'pulumi workspace file decode error' and returns early without setting the stack name — it swallows the underlying cause.","triggerScenarios":"Rendering a pulumi segment when the workspace cache file is empty, truncated, contains non-JSON content, or its schema changed between pulumi CLI versions so fields no longer match pulumiWorkSpaceFileSpec.","commonSituations":"Interrupted pulumi command leaving a partial cache file; pulumi CLI upgrade changing the workspace file layout; the user lacking read permission (FileContent returns empty string, which is invalid JSON); running in a container where ~/.pulumi doesn't exist.","solutions":["Delete the stale workspace cache file and run `pulumi stack` once so pulumi regenerates it (`rm ~/.pulumi/workspaces/*/stack-name.json`)","Check the file contains valid JSON (`cat ~/.pulumi/workspaces/*/stack-name.json | jq .`)","Reinstall/align the pulumi CLI version with the oh-my-posh expectation","The segment degrades gracefully (stack not shown) — remove the pulumi segment if you don't use pulumi"],"exampleFix":"// before\n$ cat ~/.pulumi/workspaces/*/stack-name.json\n(empty file)\n// after: regenerate\n$ rm ~/.pulumi/workspaces/*/stack-name.json && cd myproject && pulumi stack select dev","handlingStrategy":"try-catch","validationCode":"// validate the cache file parses before use\ndata, err := os.ReadFile(stackNameFile)\nif err != nil || !json.Valid(data) {\n    // delete and let pulumi regenerate\n}","typeGuard":null,"tryCatchPattern":"// segment already swallows the cause; treat empty stack as 'not in a workspace'\nif p.Stack == \"\" {\n    hideSegment()\n}","preventionTips":["Delete truncated files under ~/.pulumi/workspaces after crashes","Re-run `pulumi stack select` to regenerate the cache","Keep pulumi CLI and oh-my-posh versions aligned","Check file read permissions in containers"],"tags":["go","json","pulumi","cache","unmarshal"],"backgroundTag":"json-decode-error","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}