Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(config): reject a misspelled LOG_LEVEL at boot
Yudhi Armyndharis3c2c8f685592
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 55958d29a..3dc2bf8bf 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -37,6 +37,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0recreate changes that id by default, so with `AUTO_START_SESSIONS` off nothing revisited the row andit went on reporting an engine no process was running. The sweep now runs regardless of that flag;adopting a session still requires it.+- A misspelled `LOG_LEVEL` now fails the boot naming the five accepted values instead of silently+ logging at info (more logging than the operator asked for; Nest's `log` and Baileys' `trace` were+ silent-info typos). Mixed case and surrounding spaces still work, matching how the value is read.## [0.23.4] - 2026-09-05diff --git a/src/config/env.validation.spec.ts b/src/config/env.validation.spec.tsindex 685aa4528..f81c475e2 100644--- a/src/config/env.validation.spec.ts+++ b/src/config/env.validation.spec.ts@@ -317,6 +317,22 @@ describe('validateEnv', () => {expect(() => validateEnv({})).not.toThrow();});+ it('rejects a LOG_LEVEL misspelling instead of silently logging at info', () => {+ // Plausible spellings from neighbouring vocabularies that this repo's LogLevel does not carry;+ // every one of them silently meant INFO before this check existed.+ expect(() => validateEnv({ LOG_LEVEL: 'warning' })).toThrow(/LOG_LEVEL/);+ expect(() => validateEnv({ LOG_LEVEL: 'log' })).toThrow(/LOG_LEVEL/); // Nest's spelling+ expect(() => validateEnv({ LOG_LEVEL: 'trace' })).toThrow(/LOG_LEVEL/); // Baileys' vocabulary+ // The reader (main.ts) trims and lowercases before matching, so these keep booting.+ expect(() => validateEnv({ LOG_LEVEL: 'DEBUG' })).not.toThrow();+ expect(() => validateEnv({ LOG_LEVEL: ' warn ' })).not.toThrow();+ // The five real levels, and unset (meaning INFO), all pass.+ for (const level of ['error', 'warn', 'info', 'debug', 'verbose']) {+ expect(() => validateEnv({ LOG_LEVEL: level })).not.toThrow();+ }+ expect(() => validateEnv({})).not.toThrow();+ });+it('rejects a sqlite data DB path that collides with the internal main database file', () => {// The 'main' (auth/audit) and 'data' connections must be separate SQLite files; sharing one// file means two migration ledgers + synchronize policies on the same tables.diff --git a/src/config/env.validation.ts b/src/config/env.validation.tsindex e6a38c0b0..31d0cab4d 100644--- a/src/config/env.validation.ts+++ b/src/config/env.validation.ts@@ -480,6 +480,20 @@ export function validateEnv(config: EnvConfig): EnvConfig {errors.push(`SEARCH_PROVIDER must be one of: auto, builtin-fts, none (got ${JSON.stringify(provider)})`);}+ // LOG_LEVEL is read in main.ts by exact match after trim+toLowerCase, so any casing works today+ // and only a MISSPELLING differs: every unrecognised value silently means INFO, which is MORE+ // logging than the operator asked for (Nest-adjacent spellings like 'log', 'trace' or 'fatal'+ // included, none of them this repo's vocabulary). Validate the normalised form, mirroring the+ // read site exactly (same philosophy as MEDIA_DOWNLOAD_ENABLED above): nothing that works today+ // is refused, and a misspelling fails the boot instead of quietly logging at info.+ const LOG_LEVEL_VALUES = ['error', 'warn', 'info', 'debug', 'verbose'];+ const rawLogLevel = str('LOG_LEVEL');+ if (rawLogLevel !== undefined && !LOG_LEVEL_VALUES.includes(rawLogLevel.toLowerCase())) {+ errors.push(+ `LOG_LEVEL must be one of ${LOG_LEVEL_VALUES.map(v => `"${v}"`).join(', ')} (got ${JSON.stringify(rawLogLevel)})`,+ );+ }+if (errors.length > 0) {throw new Error(`Invalid environment configuration:\n - ${errors.join('\n - ')}`);}diff --git a/src/main.ts b/src/main.tsindex c520ad02d..63447c942 100644--- a/src/main.ts+++ b/src/main.ts@@ -35,7 +35,8 @@ import { RedisIoAdapter } from './modules/events/redis-io.adapter';let appInstance: INestApplication | undefined;async function bootstrap() {- // Apply the operator-configured log verbosity (LOG_LEVEL) before anything logs. Unset/invalid → INFO.+ // Apply the operator-configured log verbosity (LOG_LEVEL) before anything logs. Unset means INFO;+ // a misspelling never reaches here, env.validation.ts rejects it at boot.const requestedLevel = process.env.LOG_LEVEL?.trim().toLowerCase();if (requestedLevel && (Object.values(LogLevel) as string[]).includes(requestedLevel)) {LoggerService.setLogLevel(requestedLevel as LogLevel);