{"record":{"id":"0b5b773f16fc3902","repo":"JanDeDobbeleer/oh-my-posh","slug":"environment-access-is-disabled-rendering-from-rec","errorCode":null,"errorMessage":"environment access is disabled: rendering from recorded data only","messagePattern":"environment access is disabled: rendering from recorded data only","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/runtime/terminal.go","lineNumber":137,"sourceCode":"\n\tterm.cwd = correctPath(dir)\n\tlog.Debug(term.cwd)\n}\n\n// errDataOnly is what every environment probe answers with when\n// Flags.DataOnly is set. DataOnly started life in config.Segment.restoreData,\n// suppressing a segment the recorded data does not cover - but that only\n// governs the segment's own Enabled(). A writer field computed lazily by a\n// method the template calls still reached the machine long afterwards:\n// segments/git.go's StashCount() reads logs/refs/stash off disk, and\n// stashCount is unexported so no recorded data ever restores it. Rendering\n// jandedobbeleer under wasm, where there is no filesystem, failed that\n// template outright while the CLI happily read the real repository.\n//\n// Gating the environment itself rather than each such method is what makes\n// the guarantee hold for segments nobody has audited: there is no way to\n// write one that probes, because the probe primitives themselves refuse.\nvar errDataOnly = errors.New(\"environment access is disabled: rendering from recorded data only\")\n\nfunc (term *Terminal) HasFiles(pattern string) bool {\n\treturn term.HasFilesInDir(term.Pwd(), pattern)\n}\n\nfunc (term *Terminal) HasFilesInDir(dir, pattern string) bool {\n\tif term.CmdFlags != nil && term.CmdFlags.DataOnly {\n\t\treturn false\n\t}\n\tdefer log.Trace(time.Now(), pattern)\n\n\tdirEntries, err := term.readDir(dir)\n\tif err != nil {\n\t\tlog.Error(err)\n\t\tlog.Debug(\"false\")\n\t\treturn false\n\t}\n","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/runtime/terminal.go#L119-L155","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Remove or replace segments that require live environment access (e.g. those using HasParentFilePath or command execution) when rendering from recorded data.","Render in a real terminal/CLI instead of the data-only (WASM/editor) environment.","If you are extending the code, provide recorded data for the probed paths so the segment gets its answer without environment access.","Do not bypass the gate — it is the mechanism that makes data-only rendering safe."],"exampleFix":"// before: template assumes real FS\n{{ if .HasParentFilePath \".git\" }}...{{ end }}\n// after: guard for data-only mode\n{{ if and (not .Segments.EnvDisabled) (.HasParentFilePath \".git\") }}...{{ end }}","handlingStrategy":"try-catch","validationCode":"// before probing, confirm you are not in data-only mode\nif isDataOnlyRender {\n    return recordedValue // use captured data instead of env access\n}","typeGuard":"func envAccessAllowed(t *runtime.Terminal) bool {\n    // any gated probe erroring with errDataOnly means data-only mode\n    _, err := t.StatFile(\".\")\n    return !errors.Is(err, errDataOnly)\n}","tryCatchPattern":"path, err := term.HasParentFilePath(\".git\")\nif err != nil {\n    // includes errDataOnly under WASM/recorded rendering\n    return nil // hide segment, fall back to recorded data\n}","preventionTips":["Design segments so every probe has a recorded-data fallback.","Test themes in the WASM/editor environment where env access is gated.","Never bypass errDataOnly — it enforces the data-only guarantee."],"tags":["wasm","sandbox","environment","data-only"],"backgroundTag":"environment-access-disabled","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}