JanDeDobbeleer/oh-my-posh · warning
pulumi workspace file decode error
Error message
pulumi workspace file decode error
What it means
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.
Source
Thrown at src/segments/pulumi.go:99
return
}
stackNameFile := p.Name + "-" + p.workspaceSHA1 + "-" + "workspace.json"
homedir := p.env.Home()
workspaceCacheDir := filepath.Join(homedir, ".pulumi", "workspaces")
if !p.env.HasFolder(workspaceCacheDir) || !p.env.HasFilesInDir(workspaceCacheDir, stackNameFile) {
return
}
workspaceCacheFile := filepath.Join(workspaceCacheDir, stackNameFile)
workspaceCacheFileContent := p.env.FileContent(workspaceCacheFile)
var pulumiWorkspaceSpec pulumiWorkSpaceFileSpec
err := json.Unmarshal([]byte(workspaceCacheFileContent), &pulumiWorkspaceSpec)
if err != nil {
log.Error(fmt.Errorf("pulumi workspace file decode error"))
return
}
log.Debugf("pulumi stack name: %s", pulumiWorkspaceSpec.Stack)
p.Stack = pulumiWorkspaceSpec.Stack
}
func (p *Pulumi) getProjectName() error {
var kind, fileName string
for _, file := range []string{pulumiYAML, pulumiJSON} {
if p.env.HasFiles(file) {
fileName = file
kind = filepath.Ext(file)[1:]
}
}
if kind == "" {
return fmt.Errorf("no pulumi spec file found")View on GitHub (pinned to 0976794618)
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
Example fix
// before $ cat ~/.pulumi/workspaces/*/stack-name.json (empty file) // after: regenerate $ rm ~/.pulumi/workspaces/*/stack-name.json && cd myproject && pulumi stack select dev
Defensive patterns
Strategy: try-catch
Validate before calling
// validate the cache file parses before use
data, err := os.ReadFile(stackNameFile)
if err != nil || !json.Valid(data) {
// delete and let pulumi regenerate
} Try / catch
// segment already swallows the cause; treat empty stack as 'not in a workspace'
if p.Stack == "" {
hideSegment()
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- date field must be a valid number, got: %s
- no pulumi spec file found
- unknown pulumi spec file format
- pulumi stack name is empty, use `fetch_stack` property to en
- unable to get pulumi about output
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/f046c4e6e0d3a9fc.
Report an issue: GitHub.