DIYgod/RSSHub · critical · Error
Cannot start TG: ${err}
Error message
Cannot start TG: ${err} What it means
getClient calls client.start(...) with an onError callback that re-throws the underlying Telegram client start error wrapped as 'Cannot start TG: <err>'. The wrapped error is whatever caused MTProto connection/authentication to fail: bad session, auth challenge, proxy failure, or network error.
Source
Thrown at lib/routes/telegram/tglib/client.ts:39
connectionRetries: Infinity,
autoReconnect: true,
retryDelay: 3000,
maxConcurrentDownloads: Number(config.telegram.maxConcurrentDownloads ?? 10),
proxy:
config.telegram.proxy?.host && config.telegram.proxy.port && config.telegram.proxy.secret
? {
ip: config.telegram.proxy.host,
port: Number(config.telegram.proxy.port),
MTProxy: true,
secret: config.telegram.proxy.secret,
}
: undefined,
});
await client.start(
Object.assign(authParams ?? {}, {
onError: (err: Error) => {
throw new Error('Cannot start TG: ' + err);
},
}) as any
);
return client;
}
export function getFilename(x: Api.TypeMessageMedia) {
if (x instanceof Api.MessageMediaDocument) {
for (const a of (x.document as Api.Document).attributes) {
if (a instanceof Api.DocumentAttributeFilename) {
return a.fileName;
}
}
}
return x.className;
}
export function getDocument(m: Api.TypeMessageMedia) {View on GitHub (pinned to bed535e087)
Solutions
- Read the wrapped err string to identify the root cause (auth_key not found, SESSION_REVOKED, FLOOD_WAIT, proxy timeout) before changing anything.
- Regenerate TELEGRAM_SESSION and verify TELEGRAM_API_ID/TELEGRAM_API_HASH are correct for your app.
- If using config.telegram.proxy, confirm the proxy host/port/secret are reachable and valid; test without the proxy first.
- Reduce retry pressure: the connectionRetries:Infinity setting can turn a transient error into a floodwait; retry the whole feed fetch after a delay instead of relying on infinite MTProto retries.
Example fix
// before
await client.start(
Object.assign(authParams ?? {}, {
onError: (err: Error) => {
throw new Error('Cannot start TG: ' + err);
},
}) as any
);
// after: preserve the original error type for upstream handling
await client.start(
Object.assign(authParams ?? {}, {
onError: (err: Error) => {
const e = new Error('Cannot start TG: ' + err.message, { cause: err });
e.name = err.name || 'TelegramStartError';
throw e;
},
}) as any
); Defensive patterns
Strategy: try-catch
Validate before calling
import { config } from '@/config';
function canStartTelegram(): boolean {
return Boolean(config.telegram?.session) && Boolean(config.telegram?.apiId) && Boolean(config.telegram?.apiHash);
}
// do not call getClient() until canStartTelegram() is true Type guard
function telegramStartConfigComplete(): boolean {
const t = config.telegram as { session?: string; apiId?: string | number; apiHash?: string } | undefined;
return Boolean(t?.session && t?.apiHash);
} Try / catch
try {
return await getClient(authParams);
} catch (e) {
if (e instanceof Error && /Cannot start TG:/.test(e.message)) {
const cause = e.message;
if (/FLOOD_WAIT/i.test(cause)) {
await sleep(60_000);
return await getClient(authParams);
}
if (/SESSION_REVOKED|AUTH_KEY/i.test(cause)) {
throw new Error('TELEGRAM_SESSION is invalid or revoked; regenerate it.');
}
throw e;
}
throw e;
} Prevention
- Verify TELEGRAM_SESSION, TELEGRAM_API_ID, and TELEGRAM_API_HASH together before starting.
- If using a proxy, test connectivity to it before relying on client.start.
- Avoid connectionRetries:Infinity for flapping networks; it can trigger floodwaits.
- Preserve the original error (Error cause) so the wrapped message is diagnosable.
When it happens
Trigger: client.start tries to connect to Telegram over the configured (optional) MTProxy or direct connection; the start promise rejects because the session is invalid, the API credentials are wrong, the proxy is unreachable, or Telegram rate-limits the connection.
Common situations: TELEGRAM_SESSION string is malformed or logged-out; TELEGRAM_API_ID/API_HASH mismatch; a configured MTProxy (config.telegram.proxy) is down; floodwait/TooManyRequests from repeated connect attempts; connectionRetries:Infinity amplifying a flapping network.
Related errors
- Telegram Sticker Pack RSS is disabled due to the lack of <a
- TELEGRAM_SESSION is not configured
- Authentication failed. Access denied.\n${requestPath}
- Login required
- Disqus RSS is disabled due to the lack of <a href="https://d
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/d7c5db132e450ec6.
Report an issue: GitHub.