farion1231/cc-switch · warning · Error

OPENCLAW_ENV_OBJECT_REQUIRED

OPENCLAW_ENV_OBJECT_REQUIRED

Error message

OPENCLAW_ENV_OBJECT_REQUIRED

What it means

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.

Source

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

];

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 {
  return (
    typeof profile === "string" &&
    OPENCLAW_TOOL_PROFILES.includes(profile as OpenClawToolsProfile)
  );
}

export function getOpenClawToolsProfileSelectValue(profile?: string): string {
  if (!profile) {
    return OPENCLAW_UNSET_PROFILE;
  }
  return isOpenClawToolsProfile(profile)

View on GitHub (pinned to a2e22f3302)

Solutions

  1. Make the top level an object, e.g. '{ "OPENCLAW_PROFILE": "coding" }'
  2. If your source data is an array, map it into an object before feeding the editor
  3. Pre-check with a plain-object guard before parsing

Example fix

// before
raw = '["OPENCLAW_PROFILE=coding"]'; // array -> OPENCLAW_ENV_OBJECT_REQUIRED

// after
raw = '{ "OPENCLAW_PROFILE": "coding" }';
Defensive patterns

Strategy: type-guard

Validate before calling

const pre: unknown = JSON.parse(raw); // only after syntax is known good
if (!isPlainJsonObject(pre)) {
  setEditorError("Top-level value must be a JSON object");
}

Type guard

function isPlainJsonObject(v: unknown): v is Record<string, unknown> {
  return typeof v === "object" && v !== null && !Array.isArray(v);
}

Try / catch

try {
  const config = parseOpenClawEnvEditorValue(raw);
} catch (e) {
  if (e instanceof Error && e.message === "OPENCLAW_ENV_OBJECT_REQUIRED") {
    setEditorError("Env config must be an object like { \"KEY\": \"value\" }");
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: parseOpenClawEnvEditorValue('["a","b"]'), ('"hello"'), ('42'), ('null'), ('true').

Common situations: Pasting a JSON array of env entries instead of an object; leaving a template's null placeholder; wrapping the whole config in quotes.

Related errors


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