{"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":"error","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/0b5da510168914b251481654a568c3ffacd62cf4/src/components/openclaw/utils.ts#L1-L37","documentation":"Thrown by parseOpenClawEnvEditorValue in src/components/openclaw/utils.ts when the raw env-editor string is empty or contains only whitespace. It is the first of three gates the OpenClaw env configuration must pass before it is cast to OpenClawEnvConfig; JSON syntax and object shape are checked afterwards. The trim() guard means blank input (spaces, tabs, newlines) is rejected exactly like an empty string.","triggerScenarios":"Calling parseOpenClawEnvEditorValue('') or with whitespace-only text such as ' \\n\\t ' — typically the OpenClaw env editor save/apply handler running against a cleared or never-filled textarea.","commonSituations":"User clears the JSON textarea and saves; the form is submitted before editor state hydrates; a reset action sets the env value to '' while validation still fires.","solutions":["Treat blank editor input as 'no env' and skip parsing instead of calling the function","Disable the save/apply action while raw.trim() === '' and show an inline hint","Pre-check with your own blank test and surface a translated message instead of relying on the thrown sentinel"],"exampleFix":"// before\ntry {\n  const env = parseOpenClawEnvEditorValue(raw);\n} catch (error) { /* sentinel blows up here */ }\n\n// after\nif (!raw.trim()) {\n  // blank means \"no env\" — skip parsing\n} else {\n  const env = parseOpenClawEnvEditorValue(raw);\n}","handlingStrategy":"validation","validationCode":"const isBlankEnv = (raw: string): boolean => raw.trim().length === 0;\nif (isBlankEnv(raw)) {\n  // blank means \"no env\" — skip parsing instead of calling parseOpenClawEnvEditorValue\n}","typeGuard":null,"tryCatchPattern":"try {\n  const env = parseOpenClawEnvEditorValue(raw);\n} catch (error) {\n  if (error instanceof Error && error.message === 'OPENCLAW_ENV_EMPTY') {\n    // show inline \"required\" message on the editor field\n  } else {\n    throw error;\n  }\n}","preventionTips":["Gate the save button on a non-blank editor value","Decide up front whether blank means 'clear env' or 'invalid' and encode it before calling the parser","Map the OPENCLAW_ENV_* sentinel codes to translated UI messages in one place"],"tags":["openclaw","validation","env-config","json-editor"],"backgroundTag":"empty-required-input","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"}