{"record":{"id":"21808e4a21e7afac","repo":"mem0ai/mem0","slug":"openclaw-mem0-failed-to-parse-openclaw-config","errorCode":null,"errorMessage":"[openclaw-mem0] Failed to parse ${OPENCLAW_CONFIG_FILE}: ${msg}\\nFix the JSON syntax error manually before running config commands.","messagePattern":"\\[openclaw-mem0\\] Failed to parse (.+?): (.+?)\\\\nFix the JSON syntax error manually before running config commands\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"integrations/openclaw/cli/config-file.ts","lineNumber":71,"sourceCode":"  }\n\n  const text = readText(OPENCLAW_CONFIG_FILE);\n\n  // Handle empty or whitespace-only files as first-time setup\n  if (!text.trim()) {\n    return {};\n  }\n\n  try {\n    const parsed = JSON.parse(text);\n    if (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n      throw new Error(\"Config is not a JSON object\");\n    }\n    return parsed;\n  } catch (err) {\n    // Fail closed: throw so writes don't proceed with empty config\n    const msg = err instanceof Error ? err.message : String(err);\n    throw new Error(\n      `[openclaw-mem0] Failed to parse ${OPENCLAW_CONFIG_FILE}: ${msg}\\n` +\n        `Fix the JSON syntax error manually before running config commands.`,\n    );\n  }\n}\n\n/**\n * Write the full ~/.openclaw/openclaw.json.\n *\n * Re-reads the file immediately before writing and deep-merges the\n * `plugins` section so that fields written by other processes (e.g.\n * OpenClaw gateway adding `installs`, `slots`) are not clobbered.\n */\nfunction writeFullConfig(config: Record<string, unknown>): void {\n  if (!exists(OPENCLAW_CONFIG_DIR)) {\n    mkdirp(OPENCLAW_CONFIG_DIR, 0o700);\n  }\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/integrations/openclaw/cli/config-file.ts#L53-L89","documentation":"Fail-closed wrapper thrown when ~/.openclaw/openclaw.json cannot be parsed: it wraps either a JSON.parse syntax error or the 'Config is not a JSON object' shape error, and includes the file path, the underlying message, and instructions to fix it manually. The design is deliberate — writes must not proceed with an empty config because that would clobber the existing file.","triggerScenarios":"Any config read: JSON syntax errors (trailing commas, unquoted keys, comments, truncated writes), non-object top-level JSON, or a file corrupted by a concurrent process writing non-atomically. Thrown on the first config command (readText) that touches the file.","commonSituations":"Manual edit introducing a trailing comma or comment; two processes (OpenClaw gateway and the plugin) writing the file simultaneously; editor autosave mid-write leaving truncated JSON; pasting config from a blog with smart quotes.","solutions":["Run `jq . ~/.openclaw/openclaw.json` (or open it in an editor with JSON validation) — jq reports the exact line/column of the syntax error.","Fix the reported syntax error by hand; do not delete the file if it holds gateway-managed fields like plugins.installs.","If corruption came from concurrent writes, restore from backup/git and let the plugin's re-read-then-deep-merge write path (writeOpenclawConfig) handle future updates.","Only as last resort: move the file aside and re-run setup to regenerate a minimal config."],"exampleFix":"// before\n{ \"plugins\": { \"openclaw-mem0\": { \"mode\": \"platform\", } } } // trailing comma\n\n// after\n{ \"plugins\": { \"openclaw-mem0\": { \"mode\": \"platform\" } } }","handlingStrategy":"validation","validationCode":"import { readFileSync } from 'node:fs';\nfunction validateConfig(path: string): void {\n  const text = readFileSync(path, 'utf8');\n  if (!text.trim()) return; // empty = first-time setup\n  const parsed: unknown = JSON.parse(text); // throws on syntax errors\n  if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\n    throw new Error(`${path}: top-level value must be a JSON object`);\n  }\n}","typeGuard":"function isJsonObject(v: unknown): v is Record<string, unknown> {\n  return typeof v === 'object' && v !== null && !Array.isArray(v);\n}","tryCatchPattern":"try {\n  validateConfig(configPath);\n} catch (err) {\n  console.error(`Config invalid (${(err as Error).message}). Fix manually — writes are disabled to avoid clobbering the file.`);\n  process.exit(1);\n}","preventionTips":["Never hand-edit openclaw.json while the OpenClaw gateway is running.","Use a JSON-aware editor or `jq` when editing config.","Keep the file in git or a backup so corruption is recoverable."],"tags":["config","json","filesystem","fail-closed","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}