/** * Process settings read from the environment. * * Border, deliberate: settings of the PROCESS (port, timers) are unrecoverable, * so garbage in them stops the start with a readable message. Settings pointing * at EXTERNAL resources (DATA_DIR, DB_PATH) are NOT validated here - a missing * folder or a broken database must degrade softly, the panel keeps working and * shows previous data. A folder heals itself, a port does not. * * Before this existed, garbage in REFRESH_SECONDS turned into NaN, `NaN > 0` * was false and the refresh timer was never armed: the panel ran, data went * stale, and nothing was written to the log. */ /** * Reads a non-negative number from an environment value. * @param {string} name setting name, shown to the human when it is wrong * @param {string|undefined} raw value as it came from the environment * @param {number} fallback used when the setting is absent or empty */ export function numberSetting(name, raw, fallback) { const text = String(raw ?? '').trim(); if (text === '') return fallback; const value = Number(text); if (!Number.isFinite(value) || value < 0) { throw new Error(`настройка ${name}=«${text}» — это не число; ожидается неотрицательное число`); } return value; }