{"record":{"id":"680de1cf4766accf","repo":"JanDeDobbeleer/oh-my-posh","slug":"failed-to-parse-data-w","errorCode":null,"errorMessage":"failed to parse data: %w","messagePattern":"failed to parse data: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/wasm/main.go","lineNumber":119,"sourceCode":"\tvar cfg *config.Config\n\n\tvar err error\n\n\tif strings.TrimSpace(configText) == \"\" {\n\t\tcfg = config.Default(nil)\n\t} else {\n\t\tcfg, err = config.ParseBytes(format, []byte(configText))\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to parse config: %w\", err)\n\t\t}\n\t}\n\n\tvar data *config.Data\n\n\tif dataJSON != \"\" {\n\t\tdata, err = config.ParseData([]byte(dataJSON))\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to parse data: %w\", err)\n\t\t}\n\t}\n\n\t// applyData plays the same role here as the CLI image command's own\n\t// --data closure (cli/config_export_image.go, applyDataFile): it runs\n\t// against render.Config's freshly built flags before env.Init.\n\tapplyData := func(flags *runtime.Flags) error {\n\t\t// DataOnly makes the recorded data the only source a segment may\n\t\t// render from (see runtime.Flags.DataOnly's own doc comment). The\n\t\t// CLI's --data-only is an opt-in a user can leave off, in which case\n\t\t// an uncovered segment falls through to probing the real machine;\n\t\t// here that fallback would mean probing the *browser's* fake\n\t\t// environment, which can never be what a caller of this function\n\t\t// wants, so this is mandatory rather than a choice exposed to JS.\n\t\tflags.DataOnly = true\n\n\t\tif data == nil {\n\t\t\treturn nil","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/wasm/main.go#L101-L137","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nomp.render(configText, 'json', { pwd: '/home/me' }, options)\n// after\nomp.render(configText, 'json', JSON.stringify({ pwd: '/home/me' }), options)","handlingStrategy":"validation","validationCode":"function safeRender(omp, configText, format, dataJSON, options) {\n  if (dataJSON !== '') {\n    try { JSON.parse(dataJSON); }\n    catch (e) { throw new Error(`dataJSON is not valid JSON: ${e.message}`); }\n    if (typeof dataJSON !== 'string') dataJSON = JSON.stringify(dataJSON);\n  }\n  return omp.render(configText, format, dataJSON, options);\n}","typeGuard":"function isDataJSON(v) {\n  return typeof v === 'string' && (v === '' || (JSON.parse(v) !== null && typeof JSON.parse(v) === 'object' && !Array.isArray(JSON.parse(v))));\n}","tryCatchPattern":"try {\n  const svg = omp.render(cfg, 'json', dataJSON, options);\n} catch (e) {\n  if (String(e).includes('failed to parse data')) {\n    console.error('Invalid dataJSON:', e); // fall back to rendering without data\n    const svg = omp.render(cfg, 'json', '', options);\n  }\n}","preventionTips":["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."],"tags":["wasm","json","config","javascript"],"backgroundTag":"json-parse-error","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}