Hmbown/CodeWhale · error
is required
Error message
${name} is required What it means
The telegram bridge's requiredEnv reads process.env[name] and throws if the value is missing or whitespace-only, guaranteeing the bridge starts only with its mandatory configuration present. The message identifies the exact missing variable. It is a fail-fast startup guard analogous to the one in the Feishu bridge.
Solutions
- Export the named variable with a correct value and restart the bridge.
- Verify your .env/secret mechanism actually populates the process environment (echo it in a debug run or docker exec env).
- Check the variable name spelling and case against the error message.
Example fix
// before node src/index.mjs // Error: TELEGRAM_BOT_TOKEN is required // after export TELEGRAM_BOT_TOKEN="123456:ABC..." node 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("TELEGRAM_BOT_TOKEN")) {
throw new Error("TELEGRAM_BOT_TOKEN must be set 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 config: ${err.message}. Export the variable or fix your .env loading.`);
process.exit(1);
}
throw err;
} Prevention
- Document required env vars in .env.example and check them at boot.
- Ensure dotenv is imported before any code reads process.env.
- In containers, verify secret mappings with `docker exec <c> env` or an entrypoint assertion.
When it happens
Trigger: requiredEnv('NAME') is called at startup (or lazily before an API call) and process.env.NAME is undefined, empty, or contains only whitespace.
Common situations: Forgot to export the bot token/secret before launching, .env file not loaded, Docker/CI secret not wired into the container environment, or a variable renamed in a newer bridge version.
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/3eed63fd8eedf0b4.
Report an issue: GitHub.
Appendix: source
Thrown at integrations/telegram-bridge/src/index.mjs:992
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 433685b202)