Hmbown/CodeWhale · error

is required

Error message

${name} is required

What it means

The Feishu bridge validates its runtime configuration at startup via requiredEnv, which reads process.env[name] and throws if the value is missing or blank (whitespace-only). This fail-fast guard ensures the bridge never starts with an incomplete configuration, since a missing token or secret would only surface later as failed API calls. The thrown message names the exact environment variable that is absent.

Solutions

  1. Set the named environment variable (e.g. export APP_SECRET=... or add it to your deployment env/secret store) and restart the bridge.
  2. If using a .env file, confirm it is actually loaded by the process (dotenv import, docker --env-file, systemd EnvironmentFile).
  3. Check for typos between the variable name in the error and what you exported (exact, case-sensitive match).

Example fix

// before
node integrations/feishu-bridge/src/index.mjs
// Error: FEISHU_APP_SECRET is required

// after
export FEISHU_APP_SECRET="xxxx"
node integrations/feishu-bridge/src/index.mjs
Defensive patterns

Strategy: validation

Validate before calling

function hasEnv(name) {
  const v = process.env[name];
  return typeof v === "string" && v.trim().length > 0;
}
if (!hasEnv("FEISHU_APP_SECRET")) {
  throw new Error("Set FEISHU_APP_SECRET before starting the bridge");
}

Type guard

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

Try / catch

try {
  startBridge();
} catch (err) {
  if (err instanceof Error && err.message.endsWith("is required")) {
    console.error(`Missing configuration: ${err.message}. Check your env/.env setup.`);
    process.exit(1);
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling requiredEnv('X') when process.env.X is undefined, an empty string, or contains only whitespace. Happens at bridge startup for variables like APP_ID, APP_SECRET, etc.

Common situations: Developer runs the bridge without sourcing a .env file, deploys to a host where the secret was never set, or exports the variable with only spaces by accident; also common in Docker/CI where the env mapping was forgotten.

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/ddeb11a3079f0904. Report an issue: GitHub.

Appendix: source

Thrown at integrations/feishu-bridge/src/index.mjs:576

          data: body
        });
        continue;
      } catch (error) {
        canReply = false;
        console.warn("Feishu reply API failed; falling back to message create", error);
      }
    }
    await createMessage({
      params: { receive_id_type: "chat_id" },
      data: { ...body, receive_id: chatId }
    });
  }
}

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

function resolveLarkDomain(domain) {
  const normalized = String(domain || "feishu").toLowerCase();
  if (normalized === "lark") return Lark.Domain?.Lark || "https://open.larksuite.com";
  if (normalized === "feishu") return Lark.Domain?.Feishu || "https://open.feishu.cn";
  return domain;
}

View on GitHub (pinned to 433685b202)