{"record":{"id":"8409e3f4a594fc6e","repo":"farion1231/cc-switch","slug":"openclaw-env-invalid-json","errorCode":"OPENCLAW_ENV_INVALID_JSON","errorMessage":"OPENCLAW_ENV_INVALID_JSON","messagePattern":"OPENCLAW_ENV_INVALID_JSON","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/components/openclaw/utils.ts","lineNumber":26,"sourceCode":"  \"minimal\",\n  \"coding\",\n  \"messaging\",\n  \"full\",\n];\n\nexport const OPENCLAW_UNSUPPORTED_PROFILE = \"__unsupported_profile__\";\nexport const OPENCLAW_UNSET_PROFILE = \"__unset_profile__\";\n\nexport function parseOpenClawEnvEditorValue(raw: string): OpenClawEnvConfig {\n  if (!raw.trim()) {\n    throw new Error(\"OPENCLAW_ENV_EMPTY\");\n  }\n\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(raw);\n  } catch {\n    throw new Error(\"OPENCLAW_ENV_INVALID_JSON\");\n  }\n\n  if (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n    throw new Error(\"OPENCLAW_ENV_OBJECT_REQUIRED\");\n  }\n  return parsed as OpenClawEnvConfig;\n}\n\nexport function isOpenClawToolsProfile(\n  profile?: string,\n): profile is OpenClawToolsProfile {\n  return (\n    typeof profile === \"string\" &&\n    OPENCLAW_TOOL_PROFILES.includes(profile as OpenClawToolsProfile)\n  );\n}\n\nexport function getOpenClawToolsProfileSelectValue(profile?: string): string {","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/farion1231/cc-switch/blob/a2e22f330273a5b6ffa87cb8b82b624601bac562/src/components/openclaw/utils.ts#L8-L44","documentation":"Thrown when parseOpenClawEnvEditorValue receives non-empty text that JSON.parse rejects. It marks a syntax error in the OpenClaw env JSON blob, distinct from the empty-input and wrong-shape cases, so the UI can point the user at malformed JSON.","triggerScenarios":"parseOpenClawEnvEditorValue('{ \"key\": }'), ('foo'), ('{a: 1}') - unquoted keys, trailing commas, stray characters, or non-JSON config pasted in all make JSON.parse throw.","commonSituations":"Hand-editing the env JSON and breaking syntax; pasting TOML or YAML into a JSON-only editor; missing quotes around keys or values.","solutions":["Validate with JSON.parse in a debounced change handler and show the syntax error inline before save","Use a JSON-aware editor component that flags errors as the user types","If comments must be allowed, strip them (or use jsonc) before calling the parser"],"exampleFix":"// before\nconst config = parseOpenClawEnvEditorValue(raw); // throws OPENCLAW_ENV_INVALID_JSON on typo\n\n// after\ntry {\n  JSON.parse(raw);\n  setJsonError(null);\n} catch (e) {\n  setJsonError(e instanceof Error ? e.message : String(e));\n}","handlingStrategy":"try-catch","validationCode":"function tryParseJson(raw: string): { ok: true; value: unknown } | { ok: false; error: string } {\n  try {\n    return { ok: true, value: JSON.parse(raw) };\n  } catch (e) {\n    return { ok: false, error: e instanceof Error ? e.message : String(e) };\n  }\n}\n\nconst pre = tryParseJson(raw);\nif (!pre.ok) {\n  setEditorError(pre.error); // show inline before calling the real parser\n}","typeGuard":null,"tryCatchPattern":"try {\n  const config = parseOpenClawEnvEditorValue(raw);\n} catch (e) {\n  if (e instanceof Error && e.message === \"OPENCLAW_ENV_INVALID_JSON\") {\n    setEditorError(\"Fix the JSON syntax, then save again\");\n  } else {\n    throw e;\n  }\n}","preventionTips":["Use a JSON-aware editor with live syntax validation","Validate on a debounce as the user types, not only on save","Never paste TOML/YAML into a JSON-only editor"],"tags":["json","validation","openclaw","env-config"],"backgroundTag":null,"analyzedSha":"a2e22f330273a5b6ffa87cb8b82b624601bac562","analyzedAt":"2026-08-16T03:46:07.889Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}