Hmbown/CodeWhale · error

is required

Error message

${name} is required

What it means

Exported from the WeCom bridge's lib.mjs, requiredEnv reads process.env[name] and throws when the value is missing or blank. Because it is a shared library helper, it is invoked wherever any code path first needs a mandatory setting, so the error can appear at import-time initialization or just before an API call. The message names the exact missing variable.

Solutions

  1. Export the named variable with a real value and rerun.
  2. Verify the secret-injection mechanism (Docker env, k8s secret, CI variables) actually reaches the process environment.
  3. Match the variable name exactly as shown in the error, including case.

Example fix

// before
import { requiredEnv } from "./lib.mjs";  // throws: WECOM_CORP_ID is required

// after
export WECOM_CORP_ID="ww1234567890"  # then run the bridge
Defensive patterns

Strategy: validation

Validate before calling

function hasEnv(name) {
  const v = process.env[name];
  return typeof v === "string" && v.trim().length > 0;
}
for (const name of ["WECOM_CORP_ID", "WECOM_AGENT_ID", "WECOM_SECRET"]) {
  if (!hasEnv(name)) throw new Error(`${name} must be set`);
}

Type guard

const isNonEmptyString = (v) => typeof v === "string" && v.trim().length > 0;

Try / catch

try {
  initWecomBridge();
} catch (err) {
  if (err instanceof Error && err.message.endsWith("is required")) {
    console.error(`Missing WeCom configuration: ${err.message}`);
    process.exit(1);
  }
  throw err;
}

Prevention

When it happens

Trigger: requiredEnv('NAME') is called with process.env.NAME undefined, empty string, or whitespace-only — e.g. reading corpId, agentId, or secret config at startup.

Common situations: WeCom credentials never exported, secrets not injected in the deployment environment, .env file ignored by the runner, or whitespace-only values from a mishandled secret manager.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/b9dbd30f4199019c. Report an issue: GitHub.

Appendix: 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 433685b202)