moeru-ai/airi · error · Error

invalid JSON: ${stringifyError(error)}

Error message

invalid JSON: ${stringifyError(error)}

What it means

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.

Source

Thrown at apps/stage-tamagotchi/src/shared/mcp-config.ts:120

 *
 * Use when:
 * - Reading `mcp.json` from disk
 * - Applying raw JSON drafts in the renderer
 *
 * Expects:
 * - `text` contains JSON text for an MCP config file
 *
 * Returns:
 * - A validated `ElectronMcpStdioConfigFile`
 */
export function parseElectronMcpConfigText(text: string): ElectronMcpStdioConfigFile {
  let parsed: unknown

  try {
    parsed = JSON.parse(text)
  }
  catch (error) {
    throw new Error(`invalid JSON: ${stringifyError(error)}`)
  }

  return parseElectronMcpConfig(parsed)
}

View on GitHub (pinned to 27111382b4)

Solutions

  1. Run the text through a JSON linter to find the exact syntax error location cited in the message.
  2. Remove trailing commas, comments, and single quotes; double-quote all keys and string values.
  3. If authoring in TS/JS, JSON.stringify the object before writing the file rather than hand-serializing.

Example fix

// before (text)
{ "mcpServers": { "fs": { "command": "npx", } } }  // trailing comma -> invalid JSON
// after
{ "mcpServers": { "fs": { "command": "npx" } } }
Defensive patterns

Strategy: validation

Validate before calling

function tryParseJson(text) {
  try { JSON.parse(text); return null } catch (e) { return e.message }
}
const syntaxErr = tryParseJson(text)
if (syntaxErr) console.error(syntaxErr)

Type guard

function isValidJsonText(text) {
  try { JSON.parse(text); return true } catch { return false }
}

Try / catch

try {
  const cfg = parseElectronMcpConfigText(text)
} catch (e) {
  if (e.message.startsWith('invalid JSON:'))
    // point the user at the syntax location in the message
  throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12). Data as JSON: /api/errors/994999f8354cc0ee. Report an issue: GitHub.