{"record":{"id":"8f8bfc063a410eaa","repo":"farion1231/cc-switch","slug":"openclaw-env-empty","errorCode":"OPENCLAW_ENV_EMPTY","errorMessage":"OPENCLAW_ENV_EMPTY","messagePattern":"OPENCLAW_ENV_EMPTY","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/components/openclaw/utils.ts","lineNumber":19,"sourceCode":"import type {\n  OpenClawAgentsDefaults,\n  OpenClawEnvConfig,\n  OpenClawToolsProfile,\n} from \"@/types\";\n\nexport const OPENCLAW_TOOL_PROFILES: OpenClawToolsProfile[] = [\n  \"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 {","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/farion1231/cc-switch/blob/a2e22f330273a5b6ffa87cb8b82b624601bac562/src/components/openclaw/utils.ts#L1-L37","documentation":"Thrown by parseOpenClawEnvEditorValue when the raw editor text is empty or whitespace-only. It fires before JSON parsing, so the OpenClaw env editor can distinguish 'nothing was entered' from 'invalid JSON'. Expect it on any save/apply path that passes an unguarded empty string.","triggerScenarios":"Calling parseOpenClawEnvEditorValue('') or parseOpenClawEnvEditorValue('   \\n  ') - i.e. the env editor value was submitted with nothing typed after trim().","commonSituations":"User clears the env JSON textarea and hits save; a form reset leaves the field empty; automated tests call the parser with an empty fixture.","solutions":["Pre-check the value: if (!raw.trim()) treat the action as a no-op or an explicit unset instead of parsing","Disable the save button while the editor is blank","If empty means 'remove override', delete the key rather than round-tripping through the parser"],"exampleFix":"// before\nconst config = parseOpenClawEnvEditorValue(raw); // throws OPENCLAW_ENV_EMPTY on blank input\n\n// after\nif (!raw.trim()) {\n  return; // nothing to save\n}\nconst config = parseOpenClawEnvEditorValue(raw);","handlingStrategy":"validation","validationCode":"function isEmptyEnvText(raw: string): boolean {\n  return raw.trim().length === 0;\n}\n\n// before saving\nif (isEmptyEnvText(raw)) {\n  return; // nothing to save - skip the parse call\n}\nconst config = parseOpenClawEnvEditorValue(raw);","typeGuard":null,"tryCatchPattern":"try {\n  const config = parseOpenClawEnvEditorValue(raw);\n} catch (e) {\n  if (e instanceof Error && e.message === \"OPENCLAW_ENV_EMPTY\") {\n    showHint(\"Env editor is empty - nothing to save\");\n  } else {\n    throw e;\n  }\n}","preventionTips":["Disable the save action while the editor is blank","Trim input before deciding whether to parse","Treat empty input as an explicit unset action instead of a parse call"],"tags":["validation","json","openclaw","env-config"],"backgroundTag":null,"analyzedSha":"a2e22f330273a5b6ffa87cb8b82b624601bac562","analyzedAt":"2026-08-16T03:46:07.889Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}