Hmbown/CodeWhale · error · Error

${name} is required

Error message

${name} is required

What it means

requiredEnv(name) reads process.env[name] during bridge startup and throws `${name} is required` when the value is absent or whitespace-only. In the telegram bridge it guards TELEGRAM_BOT_TOKEN (index.mjs:48). The process aborts during config assembly, before any Telegram or runtime traffic occurs.

Source

Thrown at integrations/telegram-bridge/src/index.mjs:977

    signal: options.signal
  });
  const payload = await readJsonSafe(response);
  if (!response.ok || payload?.ok === false) {
    const error = new Error(
      payload?.description || `Telegram API request failed (${response.status})`
    );
    error.errorCode = payload?.error_code || response.status;
    error.description = payload?.description || "";
    error.parameters = payload?.parameters || {};
    throw error;
  }
  return payload.result;
}

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

function requiredEnvFirst(...names) {
  const value = envFirst(process.env, ...names);
  if (!value) {
    throw new Error(`${names.join(" or ")} is required`);
  }
  return value;
}

function delay(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

View on GitHub (pinned to 8880682c63)

Solutions

  1. Export a real token from @BotFather: `export TELEGRAM_BOT_TOKEN='123456:ABC-DEF...'`
  2. Verify before starting: `printenv TELEGRAM_BOT_TOKEN` should print a non-empty value
  3. For containers/services, add the variable via --env-file or the unit's Environment=, and confirm the file is loaded before config assembly

Example fix

# before
node src/index.mjs   # TELEGRAM_BOT_TOKEN unset
# after
TELEGRAM_BOT_TOKEN='123456:ABC-DEF' node src/index.mjs
Defensive patterns

Strategy: validation

Validate before calling

const botToken = process.env.TELEGRAM_BOT_TOKEN?.trim();
if (!botToken) {
  console.error('TELEGRAM_BOT_TOKEN is required — get one from @BotFather');
  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: Starting `node src/index.mjs` without TELEGRAM_BOT_TOKEN exported, or with it set to an empty or whitespace-only string (blank line in .env, `TELEGRAM_BOT_TOKEN="" node ...`).

Common situations: Forgot to source the .env file; docker run without -e or --env-file; CI secret not injected into the job; quoting or trailing-space mistake in a systemd Environment= line.

Related errors


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