JanDeDobbeleer/oh-my-posh · error
failed to parse data: %w
Error message
failed to parse data: %w
What it means
This error is returned by the WebAssembly entry point renderSVG (src/wasm/main.go:119) when the optional dataJSON argument passed to the JS render() function is not valid JSON that unmarshals into config.Data. config.ParseData wraps the underlying json.Unmarshal error, so the message is always "failed to parse data: <json error>". It exists because the wasm module renders prompts from a browser/JS caller and cannot probe the real machine, so the recorded data blob must be parsed strictly.
Source
Thrown at src/wasm/main.go:119
var cfg *config.Config
var err error
if strings.TrimSpace(configText) == "" {
cfg = config.Default(nil)
} else {
cfg, err = config.ParseBytes(format, []byte(configText))
if err != nil {
return "", fmt.Errorf("failed to parse config: %w", err)
}
}
var data *config.Data
if dataJSON != "" {
data, err = config.ParseData([]byte(dataJSON))
if err != nil {
return "", fmt.Errorf("failed to parse data: %w", err)
}
}
// applyData plays the same role here as the CLI image command's own
// --data closure (cli/config_export_image.go, applyDataFile): it runs
// against render.Config's freshly built flags before env.Init.
applyData := func(flags *runtime.Flags) error {
// DataOnly makes the recorded data the only source a segment may
// render from (see runtime.Flags.DataOnly's own doc comment). The
// CLI's --data-only is an opt-in a user can leave off, in which case
// an uncovered segment falls through to probing the real machine;
// here that fallback would mean probing the *browser's* fake
// environment, which can never be what a caller of this function
// wants, so this is mandatory rather than a choice exposed to JS.
flags.DataOnly = true
if data == nil {
return nilView on GitHub (pinned to 0976794618)
Solutions
- Validate the JSON before calling render(): JSON.parse(dataJSON) in the browser console to see the raw syntax error the wasm error wraps.
- Ensure the object matches config.Data's shape (strings for env-like keys such as pwd/status, objects for maps) and stringify it: JSON.stringify({pwd: '/home/me', status: 0}) -> pass as string.
- If you don't need recorded data, pass an empty string '' for dataJSON so parsing is skipped and the default environment is used.
- Check the nested wrapped error for the exact JSON path/type mismatch and fix that field.
Example fix
// before
omp.render(configText, 'json', { pwd: '/home/me' }, options)
// after
omp.render(configText, 'json', JSON.stringify({ pwd: '/home/me' }), options) Defensive patterns
Strategy: validation
Validate before calling
function safeRender(omp, configText, format, dataJSON, options) {
if (dataJSON !== '') {
try { JSON.parse(dataJSON); }
catch (e) { throw new Error(`dataJSON is not valid JSON: ${e.message}`); }
if (typeof dataJSON !== 'string') dataJSON = JSON.stringify(dataJSON);
}
return omp.render(configText, format, dataJSON, options);
} Type guard
function isDataJSON(v) {
return typeof v === 'string' && (v === '' || (JSON.parse(v) !== null && typeof JSON.parse(v) === 'object' && !Array.isArray(JSON.parse(v))));
} Try / catch
try {
const svg = omp.render(cfg, 'json', dataJSON, options);
} catch (e) {
if (String(e).includes('failed to parse data')) {
console.error('Invalid dataJSON:', e); // fall back to rendering without data
const svg = omp.render(cfg, 'json', '', options);
}
} Prevention
- Always JSON.stringify() JavaScript objects before passing them as dataJSON.
- Validate data blobs against config.Data's expected keys and types before calling render.
- Pass an empty string when no recorded data is needed - parsing is skipped entirely.
- Generate data blobs programmatically (e.g. from oh-my-posh's own data output) instead of hand-writing them.
When it happens
Trigger: Calling the wasm render(configText, format, dataJSON, options) function with a non-empty third argument that is malformed JSON, valid JSON of the wrong shape (e.g. an array instead of an object), or JSON with fields of the wrong type (e.g. "status": 1 instead of a string). An empty dataJSON string never triggers it - the argument is skipped entirely.
Common situations: Hand-writing JSON data blobs in a browser studio/preview instead of generating them from config.NewData; passing a JavaScript object without JSON.stringify()-ing it first; double-encoded JSON (a JSON string containing JSON); upgrading oh-my-posh and using a data schema key that changed name or type.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to parse data file: %w
- failed to parse version in data file: %w
- failed to parse segments in data file: %w
- failed to parse env data: %w
- render expects 4 arguments (configText, format, dataJSON, op
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/680de1cf4766accf.
Report an issue: GitHub.