V17.4.3 — surface the actual error in "Bot error: ..." logs
Quick patch on top of V17.4.2 addressing @petermeter69's observation on #442:
"SLIGHTLYBETTEREFATAL output showed the error code in the past. Now it is AggregateError. Is there a chance to get more details from it in case of an error?"
What was happening
node-telegram-bot-api wraps failed requests in a RequestError, which wraps Node's AggregateError (the dual-stack IPv4-and-IPv6 connect failure shape), which contains the actual connect ETIMEDOUT <ip>:443 entries in an .errors[] array. Our bot.on('error', ...) handler logged just error.message, which on a FatalError wrapping that whole structure is the bare string 'AggregateError' — accurate but useless for diagnosis.
What changes in V17.4.3
A new formatErrorChain(error) helper at the top of bot-node.js walks the error.cause chain and any nested AggregateError.errors arrays down to the leaf messages, deduplicates them, and joins with ; . Hooked into two places: the 'Bot error: ...' warn on fatal errors, and the verbose polling_error log.
Side-by-side for petermeter69's #442 trace:
V17.4.2: Bot error: AggregateError
V17.4.3: Bot error: connect ETIMEDOUT 149.154.166.110:443; connect ETIMEDOUT 2001:b28:f23d:f001::a:443
Both IPv4 and IPv6 leaves appear in the headline, so the operator immediately sees:
- the underlying syscall (
connect ETIMEDOUT), - both target IPs (or just one if only one stack was tried),
- which lets them decide whether to force
addressFamily: 4(the typical fix when only the IPv6 path is broken), check DNS, runmtr, etc.
The verbose util.inspect(error, { depth: 5 }) dump that follows in verbose mode is unchanged — that's still available for the cases where the leaf-level summary isn't enough.
No behaviour change beyond the log format
The auto-restart / backoff / single-flight from V17.4.0 / V17.4.1 / V17.4.2 are all unchanged. formatErrorChain is also passed to scheduleRestart as the reason argument, so the "Bot will restart in Xms (reason)" line carries the same actionable text instead of the wrapper labels.
Tests
Eight new mocha cases in test/nodes/bot-node-helpers.test.js covering plain Error, linear cause chain, AggregateError multi-leaf, the actual #442 nested shape, leaf deduplication, cycle safety, 10-deep recursion cap, and shape-less input fallback. 216 passing.
What to look for after upgrading
If you still see Bot error: ... lines after V17.4.3, they'll now carry the actual diagnostic in the headline. Common shapes:
| Headline you'll see | Probable cause / fix |
|---|---|
connect ETIMEDOUT 149.154.166.110:443; connect ETIMEDOUT 2001:b28:...:443
| Both v4 and v6 paths to Telegram broken — usually a sustained connectivity outage |
connect ETIMEDOUT 2001:b28:...:443 (v6 only)
| IPv6 path broken, v4 not tried — try setting Address family to 4 on the bot config
|
getaddrinfo EAI_AGAIN api.telegram.org
| DNS resolution failed — check /etc/resolv.conf, try 1.1.1.1
|
socket hang up
| TCP RST mid-request — usually transient |
ETELEGRAM: 401 Unauthorized
| Bot token is wrong / revoked |