{"record":{"id":"0c24da1efa1ebf08","repo":"farion1231/cc-switch","slug":"openclaw-env-object-required","errorCode":"OPENCLAW_ENV_OBJECT_REQUIRED","errorMessage":"OPENCLAW_ENV_OBJECT_REQUIRED","messagePattern":"OPENCLAW_ENV_OBJECT_REQUIRED","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/components/openclaw/utils.ts","lineNumber":30,"sourceCode":"];\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 {\n  if (!profile) {\n    return OPENCLAW_UNSET_PROFILE;\n  }\n  return isOpenClawToolsProfile(profile)","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/farion1231/cc-switch/blob/a2e22f330273a5b6ffa87cb8b82b624601bac562/src/components/openclaw/utils.ts#L12-L48","documentation":"Thrown when the text is valid JSON but the top-level value is not a plain object: null, an array, a string, a number, or a boolean are all rejected. OpenClawEnvConfig is a record-shaped object, so only an object literal at the top level is accepted.","triggerScenarios":"parseOpenClawEnvEditorValue('[\"a\",\"b\"]'), ('\"hello\"'), ('42'), ('null'), ('true').","commonSituations":"Pasting a JSON array of env entries instead of an object; leaving a template's null placeholder; wrapping the whole config in quotes.","solutions":["Make the top level an object, e.g. '{ \"OPENCLAW_PROFILE\": \"coding\" }'","If your source data is an array, map it into an object before feeding the editor","Pre-check with a plain-object guard before parsing"],"exampleFix":"// before\nraw = '[\"OPENCLAW_PROFILE=coding\"]'; // array -> OPENCLAW_ENV_OBJECT_REQUIRED\n\n// after\nraw = '{ \"OPENCLAW_PROFILE\": \"coding\" }';","handlingStrategy":"type-guard","validationCode":"const pre: unknown = JSON.parse(raw); // only after syntax is known good\nif (!isPlainJsonObject(pre)) {\n  setEditorError(\"Top-level value must be a JSON object\");\n}","typeGuard":"function isPlainJsonObject(v: unknown): v is Record<string, unknown> {\n  return typeof v === \"object\" && v !== null && !Array.isArray(v);\n}","tryCatchPattern":"try {\n  const config = parseOpenClawEnvEditorValue(raw);\n} catch (e) {\n  if (e instanceof Error && e.message === \"OPENCLAW_ENV_OBJECT_REQUIRED\") {\n    setEditorError(\"Env config must be an object like { \\\"KEY\\\": \\\"value\\\" }\");\n  } else {\n    throw e;\n  }\n}","preventionTips":["Schema-check editor content before save","Document that the env config must be a flat JSON object","Seed the editor with a valid object example so users start from a correct shape"],"tags":["json","type-safety","openclaw","env-config"],"backgroundTag":null,"analyzedSha":"a2e22f330273a5b6ffa87cb8b82b624601bac562","analyzedAt":"2026-08-16T03:46:07.889Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}