farion1231/cc-switch · warning · Error

OPENCLAW_ENV_EMPTY

OPENCLAW_ENV_EMPTY

Error message

OPENCLAW_ENV_EMPTY

What it means

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.

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 a2e22f3302)

Solutions

  1. Pre-check the value: if (!raw.trim()) treat the action as a no-op or an explicit unset instead of parsing
  2. Disable the save button while the editor is blank
  3. If empty means 'remove override', delete the key rather than round-tripping through the parser

Example fix

// before
const config = parseOpenClawEnvEditorValue(raw); // throws OPENCLAW_ENV_EMPTY on blank input

// after
if (!raw.trim()) {
  return; // nothing to save
}
const config = parseOpenClawEnvEditorValue(raw);
Defensive patterns

Strategy: validation

Validate before calling

function isEmptyEnvText(raw: string): boolean {
  return raw.trim().length === 0;
}

// before saving
if (isEmptyEnvText(raw)) {
  return; // nothing to save - skip the parse call
}
const config = parseOpenClawEnvEditorValue(raw);

Try / catch

try {
  const config = parseOpenClawEnvEditorValue(raw);
} catch (e) {
  if (e instanceof Error && e.message === "OPENCLAW_ENV_EMPTY") {
    showHint("Env editor is empty - nothing to save");
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Calling parseOpenClawEnvEditorValue('') or parseOpenClawEnvEditorValue(' \n ') - i.e. the env editor value was submitted with nothing typed after trim().

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

Related errors


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