farion1231/cc-switch · error · Error

OPENCLAW_ENV_EMPTY

OPENCLAW_ENV_EMPTY

Error message

OPENCLAW_ENV_EMPTY

What it means

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.

Solutions

  1. Treat blank editor input as 'no env' and skip parsing instead of calling the function
  2. Disable the save/apply action while raw.trim() === '' and show an inline hint
  3. Pre-check with your own blank test and surface a translated message instead of relying on the thrown sentinel

Example fix

// before
try {
  const env = parseOpenClawEnvEditorValue(raw);
} catch (error) { /* sentinel blows up here */ }

// after
if (!raw.trim()) {
  // blank means "no env" — skip parsing
} else {
  const env = parseOpenClawEnvEditorValue(raw);
}
Defensive patterns

Strategy: validation

Validate before calling

const isBlankEnv = (raw: string): boolean => raw.trim().length === 0;
if (isBlankEnv(raw)) {
  // blank means "no env" — skip parsing instead of calling parseOpenClawEnvEditorValue
}

Try / catch

try {
  const env = parseOpenClawEnvEditorValue(raw);
} catch (error) {
  if (error instanceof Error && error.message === 'OPENCLAW_ENV_EMPTY') {
    // show inline "required" message on the editor field
  } else {
    throw error;
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of farion1231/cc-switch@0b5da51016 (2026-08-20). Data as JSON: /api/errors/8f8bfc063a410eaa. Report an issue: GitHub.

Appendix: source

Thrown at src/components/openclaw/utils.ts:19

import type {
  OpenClawAgentsDefaults,
  OpenClawEnvConfig,
  OpenClawToolsProfile,
} from "@/types";

export const OPENCLAW_TOOL_PROFILES: OpenClawToolsProfile[] = [
  "minimal",
  "coding",
  "messaging",
  "full",
];

export const OPENCLAW_UNSUPPORTED_PROFILE = "__unsupported_profile__";
export const OPENCLAW_UNSET_PROFILE = "__unset_profile__";

export function parseOpenClawEnvEditorValue(raw: string): OpenClawEnvConfig {
  if (!raw.trim()) {
    throw new Error("OPENCLAW_ENV_EMPTY");
  }

  let parsed: unknown;
  try {
    parsed = JSON.parse(raw);
  } catch {
    throw new Error("OPENCLAW_ENV_INVALID_JSON");
  }

  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
    throw new Error("OPENCLAW_ENV_OBJECT_REQUIRED");
  }
  return parsed as OpenClawEnvConfig;
}

export function isOpenClawToolsProfile(
  profile?: string,
): profile is OpenClawToolsProfile {

View on GitHub (pinned to 0b5da51016)