Hmbown/CodeWhale · error · Error

${name} is required

Error message

${name} is required

What it means

wecom-bridge's lib.mjs requiredEnv(name) throws `${name} is required` when the env var is unset or whitespace-only. The WeCom bridge requires WECOM_BOT_ID (index.mjs:37), WECOM_BOT_SECRET (index.mjs:38) and CODEWHALE_RUNTIME_TOKEN (index.mjs:40); the message names whichever one is missing. Startup aborts before any WeCom or runtime call.

Source

Thrown at integrations/wecom-bridge/src/lib.mjs:36

export {
  activeTurnBlock,
  cleanEnvValue,
  compactRuntimeError,
  isPlaceholderValue,
  latestRunningTurn,
  parseApprovalDecisionArgs,
  parseBool,
  parseCommand,
  parseList,
  preservedChatStateFields,
  splitMessage
};

export function requiredEnv(name) {
  const value = process.env[name];
  if (!value || !value.trim()) {
    throw new Error(`${name} is required`);
  }
  return value.trim();
}

export function parseTextContent(content) {
  return coreParseTextContent(content, ["text"]);
}

export function incomingIdentity(body) {
  const from = body?.from || {};
  const chatId = body.chatid || (body.chattype === "single" && from.userid ? `single:${from.userid}` : "");
  return {
    chatId,
    messageId: body.msgid || "",
    chatType: body.chattype || "single",
    userId: from.userid || "",
    aibotId: body.aibotid || ""
  };

View on GitHub (pinned to 8880682c63)

Solutions

  1. Set WECOM_BOT_ID and WECOM_BOT_SECRET from the WeCom app's credential page
  2. Set CODEWHALE_RUNTIME_TOKEN to the token the Codewhale runtime accepts
  3. Identify the missing one with `printenv WECOM_BOT_ID WECOM_BOT_SECRET CODEWHALE_RUNTIME_TOKEN` and restart once all print non-empty

Example fix

# before
node src/index.mjs
# after
WECOM_BOT_ID='xxx' WECOM_BOT_SECRET='yyy' CODEWHALE_RUNTIME_TOKEN='zzz' node src/index.mjs
Defensive patterns

Strategy: validation

Validate before calling

for (const name of ['WECOM_BOT_ID', 'WECOM_BOT_SECRET', 'CODEWHALE_RUNTIME_TOKEN']) {
  if (!process.env[name]?.trim()) {
    console.error(`${name} is required`);
    process.exit(2);
  }
}

Try / catch

try {
  startBridge();
} catch (error) {
  if (/is required$/.test(error.message)) {
    console.error(`Missing environment variable: ${error.message}`);
    process.exit(2);
  }
  throw error;
}

Prevention

When it happens

Trigger: Launching the WeCom bridge without one of WECOM_BOT_ID, WECOM_BOT_SECRET, or CODEWHALE_RUNTIME_TOKEN exported, or with whitespace-only values.

Common situations: WeCom app credentials never copied from the WeCom admin console into .env; container unit missing one variable; a secret removed or renamed during rotation.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/b9dbd30f4199019c. Report an issue: GitHub.