Skip to content

Commit 8d19cc4

Browse files
committed
fix(telegram): route polling diagnostics away from errors
1 parent 16ef041 commit 8d19cc4

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

extensions/telegram/src/monitor.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,19 @@ describe("monitorTelegramProvider (grammY)", () => {
472472
expect(runOptions?.runner?.retryInterval).toBe("exponential");
473473
});
474474

475+
it("logs polling startup diagnostics without using the error channel", async () => {
476+
const runtime = {
477+
log: vi.fn(),
478+
error: vi.fn(),
479+
exit: vi.fn(),
480+
};
481+
482+
await monitorWithAutoAbort({ runtime });
483+
484+
expect(runtime.log).toHaveBeenCalledWith(expect.stringContaining("polling cycle started"));
485+
expect(runtime.error).not.toHaveBeenCalled();
486+
});
487+
475488
it("requires mention in groups by default", async () => {
476489
for (const v of Object.values(api)) {
477490
if (typeof v === "function" && "mockReset" in v) {

extensions/telegram/src/monitor.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ async function loadTelegramMonitorWebhookRuntime() {
108108
}
109109

110110
export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
111-
const log = opts.runtime?.error ?? console.error;
111+
const log = (line: string) => (opts.runtime?.log ?? console.log)(line);
112+
const logError = (line: string) => (opts.runtime?.error ?? console.error)(line);
112113
let pollingSession: TelegramPollingSessionInstance | undefined;
113114

114115
const handlePollingNetworkFailure = (err: unknown, label: string) => {
@@ -231,7 +232,7 @@ export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
231232
try {
232233
await deleteTelegramUpdateOffset({ accountId: account.accountId });
233234
} catch (err) {
234-
(opts.runtime?.error ?? console.error)(
235+
logError(
235236
`telegram: failed to delete stale update offset after rotation: ${String(err)}`,
236237
);
237238
}
@@ -261,9 +262,7 @@ export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
261262
botToken: token,
262263
});
263264
} catch (err) {
264-
(opts.runtime?.error ?? console.error)(
265-
`telegram: failed to persist update offset: ${String(err)}`,
266-
);
265+
logError(`telegram: failed to persist update offset: ${String(err)}`);
267266
}
268267
};
269268

0 commit comments

Comments
 (0)