mem0ai/mem0 · error · Error
[openclaw-mem0] Failed to parse ${OPENCLAW_CONFIG_FILE}: ${m
Error message
[openclaw-mem0] Failed to parse ${OPENCLAW_CONFIG_FILE}: ${msg}\nFix the JSON syntax error manually before running config commands. What it means
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.
Source
Thrown at integrations/openclaw/cli/config-file.ts:71
}
const text = readText(OPENCLAW_CONFIG_FILE);
// Handle empty or whitespace-only files as first-time setup
if (!text.trim()) {
return {};
}
try {
const parsed = JSON.parse(text);
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
throw new Error("Config is not a JSON object");
}
return parsed;
} catch (err) {
// Fail closed: throw so writes don't proceed with empty config
const msg = err instanceof Error ? err.message : String(err);
throw new Error(
`[openclaw-mem0] Failed to parse ${OPENCLAW_CONFIG_FILE}: ${msg}\n` +
`Fix the JSON syntax error manually before running config commands.`,
);
}
}
/**
* Write the full ~/.openclaw/openclaw.json.
*
* Re-reads the file immediately before writing and deep-merges the
* `plugins` section so that fields written by other processes (e.g.
* OpenClaw gateway adding `installs`, `slots`) are not clobbered.
*/
function writeFullConfig(config: Record<string, unknown>): void {
if (!exists(OPENCLAW_CONFIG_DIR)) {
mkdirp(OPENCLAW_CONFIG_DIR, 0o700);
}
View on GitHub (pinned to 001c235229)
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.
Example fix
// before
{ "plugins": { "openclaw-mem0": { "mode": "platform", } } } // trailing comma
// after
{ "plugins": { "openclaw-mem0": { "mode": "platform" } } } Defensive patterns
Strategy: validation
Validate before calling
import { readFileSync } from 'node:fs';
function validateConfig(path: string): void {
const text = readFileSync(path, 'utf8');
if (!text.trim()) return; // empty = first-time setup
const parsed: unknown = JSON.parse(text); // throws on syntax errors
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
throw new Error(`${path}: top-level value must be a JSON object`);
}
} Type guard
function isJsonObject(v: unknown): v is Record<string, unknown> {
return typeof v === 'object' && v !== null && !Array.isArray(v);
} Try / catch
try {
validateConfig(configPath);
} catch (err) {
console.error(`Config invalid (${(err as Error).message}). Fix manually — writes are disabled to avoid clobbering the file.`);
process.exit(1);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Config is not a JSON object
- Unknown LLM provider: ${providerId}
- Unknown embedder provider: ${providerId}
- ${label} has unknown keys: ${unknown.join(", ")}
- openclaw-mem0 config required
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/21808e4a21e7afac.
Report an issue: GitHub.