{"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":"error","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/0b5da510168914b251481654a568c3ffacd62cf4/src/components/openclaw/utils.ts#L8-L44","documentation":"Thrown when JSON.parse rejects the (non-blank) env editor string while parsing an OpenClaw env configuration. The original SyntaxError is deliberately swallowed and re-thrown as the sentinel OPENCLAW_ENV_INVALID_JSON so callers can branch on a stable code. It fires only after the empty-string gate has passed, so the input always contains visible characters that are not valid JSON.","triggerScenarios":"parseOpenClawEnvEditorValue receives text like '{ \"tools\": ' (truncated paste), keys in single quotes, trailing commas, or a bare word such as none.","commonSituations":"Hand-typed JSON with a missing brace; pasting from a terminal that mangled quotes; mixing YAML ('key: value') into a JSON editor.","solutions":["Run JSON.parse in a scratch try/catch first and show the syntax error's line/column to the user","Use a JSON-aware editor component that lints or repairs on paste","Validate on blur so the user gets feedback before hitting save"],"exampleFix":"// before\nconst env = parseOpenClawEnvEditorValue(raw); // throws OPENCLAW_ENV_INVALID_JSON\n\n// after\ntry {\n  JSON.parse(raw);\n} catch (e) {\n  showEditorError(`JSON syntax: ${(e as Error).message}`);\n  return;\n}\nconst env = parseOpenClawEnvEditorValue(raw);","handlingStrategy":"validation","validationCode":"try {\n  JSON.parse(raw);\n} catch (e) {\n  showEditorError(`JSON syntax: ${(e as Error).message}`);\n  return;\n}\nconst env = parseOpenClawEnvEditorValue(raw);","typeGuard":null,"tryCatchPattern":"try {\n  const env = parseOpenClawEnvEditorValue(raw);\n} catch (error) {\n  if (error instanceof Error && error.message === 'OPENCLAW_ENV_INVALID_JSON') {\n    // point the user at the syntax problem; keep them in the editor\n  } else {\n    throw error;\n  }\n}","preventionTips":["Use a JSON-linting editor component for the env field","Validate on blur, not only on save","Run scratch JSON.parse and surface its precise message instead of the sentinel when detail helps"],"tags":["openclaw","json","validation","env-config"],"backgroundTag":"json-parse-error","analyzedSha":"0b5da510168914b251481654a568c3ffacd62cf4","analyzedAt":"2026-08-20T14:29:00.113Z","contentChangedAt":"2026-08-20T14:29:00.113Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}