{"record":{"id":"994999f8354cc0ee","repo":"moeru-ai/airi","slug":"invalid-json-stringifyerror-error","errorCode":null,"errorMessage":"invalid JSON: ${stringifyError(error)}","messagePattern":"invalid JSON: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/stage-tamagotchi/src/shared/mcp-config.ts","lineNumber":120,"sourceCode":" *\n * Use when:\n * - Reading `mcp.json` from disk\n * - Applying raw JSON drafts in the renderer\n *\n * Expects:\n * - `text` contains JSON text for an MCP config file\n *\n * Returns:\n * - A validated `ElectronMcpStdioConfigFile`\n */\nexport function parseElectronMcpConfigText(text: string): ElectronMcpStdioConfigFile {\n  let parsed: unknown\n\n  try {\n    parsed = JSON.parse(text)\n  }\n  catch (error) {\n    throw new Error(`invalid JSON: ${stringifyError(error)}`)\n  }\n\n  return parseElectronMcpConfig(parsed)\n}\n","sourceCodeStart":102,"sourceCodeEnd":125,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/apps/stage-tamagotchi/src/shared/mcp-config.ts#L102-L125","documentation":"Thrown by parseElectronMcpConfigText when JSON.parse fails on the supplied text. It wraps the native SyntaxError message via stringifyError so the caller sees the original JSON parse reason (e.g. unexpected token). This is purely a syntax-layer failure distinct from the schema validation in parseElectronMcpConfig which runs afterward on successfully parsed text.","triggerScenarios":"Loading mcp.json text that has a trailing comma, single quotes, an unquoted key, a stray comment, or is truncated; pasting a JS object literal (not JSON) into the config editor; a file with a BOM or mixed encoding.","commonSituations":"Editing mcp.json by hand and using JavaScript syntax (comments, trailing commas, unquoted keys) instead of strict JSON; copy-pasting a config snippet that lost a closing brace; CRLF/encoding artifacts from a non-UTF-8 editor.","solutions":["Run the text through a JSON linter to find the exact syntax error location cited in the message.","Remove trailing commas, comments, and single quotes; double-quote all keys and string values.","If authoring in TS/JS, JSON.stringify the object before writing the file rather than hand-serializing."],"exampleFix":"// before (text)\n{ \"mcpServers\": { \"fs\": { \"command\": \"npx\", } } }  // trailing comma -> invalid JSON\n// after\n{ \"mcpServers\": { \"fs\": { \"command\": \"npx\" } } }","handlingStrategy":"validation","validationCode":"function tryParseJson(text) {\n  try { JSON.parse(text); return null } catch (e) { return e.message }\n}\nconst syntaxErr = tryParseJson(text)\nif (syntaxErr) console.error(syntaxErr)","typeGuard":"function isValidJsonText(text) {\n  try { JSON.parse(text); return true } catch { return false }\n}","tryCatchPattern":"try {\n  const cfg = parseElectronMcpConfigText(text)\n} catch (e) {\n  if (e.message.startsWith('invalid JSON:'))\n    // point the user at the syntax location in the message\n  throw e\n}","preventionTips":["Author mcp.json by JSON.stringify-ing an object, not by hand.","Run the editor's JSON validator before saving.","Avoid comments, trailing commas, and single quotes in mcp.json."],"tags":["mcp","config","json","validation","shared"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}