JanDeDobbeleer/oh-my-posh · info

environment access is disabled: rendering from recorded data

Error message

environment access is disabled: rendering from recorded data only

What it means

errDataOnly is the sentinel error guarding oh-my-posh's data-only (recorded) rendering mode, used e.g. under WASM where there is no filesystem. Instead of auditing every segment, the environment primitive methods themselves (StatFile, ResolveSymlink, RunCommandWithEnv, HTTPRequest, HasParentFilePath, etc.) refuse to execute and return this error, guaranteeing no segment can probe the real environment when rendering from recorded data.

Source

Thrown at src/runtime/terminal.go:137

	term.cwd = correctPath(dir)
	log.Debug(term.cwd)
}

// errDataOnly is what every environment probe answers with when
// Flags.DataOnly is set. DataOnly started life in config.Segment.restoreData,
// suppressing a segment the recorded data does not cover - but that only
// governs the segment's own Enabled(). A writer field computed lazily by a
// method the template calls still reached the machine long afterwards:
// segments/git.go's StashCount() reads logs/refs/stash off disk, and
// stashCount is unexported so no recorded data ever restores it. Rendering
// jandedobbeleer under wasm, where there is no filesystem, failed that
// template outright while the CLI happily read the real repository.
//
// Gating the environment itself rather than each such method is what makes
// the guarantee hold for segments nobody has audited: there is no way to
// write one that probes, because the probe primitives themselves refuse.
var errDataOnly = errors.New("environment access is disabled: rendering from recorded data only")

func (term *Terminal) HasFiles(pattern string) bool {
	return term.HasFilesInDir(term.Pwd(), pattern)
}

func (term *Terminal) HasFilesInDir(dir, pattern string) bool {
	if term.CmdFlags != nil && term.CmdFlags.DataOnly {
		return false
	}
	defer log.Trace(time.Now(), pattern)

	dirEntries, err := term.readDir(dir)
	if err != nil {
		log.Error(err)
		log.Debug("false")
		return false
	}

View on GitHub (pinned to 0976794618)

Solutions

  1. Remove or replace segments that require live environment access (e.g. those using HasParentFilePath or command execution) when rendering from recorded data.
  2. Render in a real terminal/CLI instead of the data-only (WASM/editor) environment.
  3. If you are extending the code, provide recorded data for the probed paths so the segment gets its answer without environment access.
  4. Do not bypass the gate — it is the mechanism that makes data-only rendering safe.

Example fix

// before: template assumes real FS
{{ if .HasParentFilePath ".git" }}...{{ end }}
// after: guard for data-only mode
{{ if and (not .Segments.EnvDisabled) (.HasParentFilePath ".git") }}...{{ end }}
Defensive patterns

Strategy: try-catch

Validate before calling

// before probing, confirm you are not in data-only mode
if isDataOnlyRender {
    return recordedValue // use captured data instead of env access
}

Type guard

func envAccessAllowed(t *runtime.Terminal) bool {
    // any gated probe erroring with errDataOnly means data-only mode
    _, err := t.StatFile(".")
    return !errors.Is(err, errDataOnly)
}

Try / catch

path, err := term.HasParentFilePath(".git")
if err != nil {
    // includes errDataOnly under WASM/recorded rendering
    return nil // hide segment, fall back to recorded data
}

Prevention

When it happens

Trigger: Any call to the gated Terminal environment methods — StatFile, ResolveSymlink, RunCommandWithEnv, HTTPRequest, HasParentFilePath — while the terminal is configured in data-only mode (recorded data rendering).

Common situations: Rendering prompts from recorded/captured data in the browser/WASM playground; using the online theme editor; a segment that needs real environment probing is included in a data-only render.

Related errors


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/0b5b773f16fc3902. Report an issue: GitHub.