fix(logging): trim provider log prefixes
This commit is contained in:
@@ -94,11 +94,11 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
|||||||
const guildHistories = new Map<string, DiscordHistoryEntry[]>();
|
const guildHistories = new Map<string, DiscordHistoryEntry[]>();
|
||||||
|
|
||||||
client.once(Events.ClientReady, () => {
|
client.once(Events.ClientReady, () => {
|
||||||
runtime.log?.(`discord: logged in as ${client.user?.tag ?? "unknown"}`);
|
runtime.log?.(`logged in as ${client.user?.tag ?? "unknown"}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on(Events.Error, (err) => {
|
client.on(Events.Error, (err) => {
|
||||||
runtime.error?.(danger(`discord client error: ${String(err)}`));
|
runtime.error?.(danger(`client error: ${String(err)}`));
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on(Events.MessageCreate, async (message) => {
|
client.on(Events.MessageCreate, async (message) => {
|
||||||
@@ -294,7 +294,7 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
|||||||
guildHistories.set(message.channelId, []);
|
guildHistories.set(message.channelId, []);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
runtime.error?.(danger(`Discord handler failed: ${String(err)}`));
|
runtime.error?.(danger(`handler failed: ${String(err)}`));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -427,6 +427,6 @@ async function deliverReplies({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
runtime.log?.(`discord: delivered reply to ${target}`);
|
runtime.log?.(`delivered reply to ${target}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ async function waitForSignalDaemonReady(params: {
|
|||||||
|
|
||||||
params.runtime.error?.(
|
params.runtime.error?.(
|
||||||
danger(
|
danger(
|
||||||
`signal: daemon not ready after ${params.timeoutMs}ms (${lastError ?? "unknown error"})`,
|
`daemon not ready after ${params.timeoutMs}ms (${lastError ?? "unknown error"})`,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
throw new Error(`signal daemon not ready (${lastError ?? "unknown error"})`);
|
throw new Error(`signal daemon not ready (${lastError ?? "unknown error"})`);
|
||||||
@@ -207,7 +207,7 @@ async function deliverReplies(params: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
runtime.log?.(`signal: delivered reply to ${target}`);
|
runtime.log?.(`delivered reply to ${target}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,13 +267,11 @@ export async function monitorSignalProvider(
|
|||||||
try {
|
try {
|
||||||
payload = JSON.parse(event.data) as SignalReceivePayload;
|
payload = JSON.parse(event.data) as SignalReceivePayload;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
runtime.error?.(`signal: failed to parse event: ${String(err)}`);
|
runtime.error?.(`failed to parse event: ${String(err)}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (payload?.exception?.message) {
|
if (payload?.exception?.message) {
|
||||||
runtime.error?.(
|
runtime.error?.(`receive exception: ${payload.exception.message}`);
|
||||||
`signal: receive exception: ${payload.exception.message}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
const envelope = payload?.envelope;
|
const envelope = payload?.envelope;
|
||||||
if (!envelope) return;
|
if (!envelope) return;
|
||||||
@@ -317,9 +315,7 @@ export async function monitorSignalProvider(
|
|||||||
fetched.contentType ?? firstAttachment.contentType ?? undefined;
|
fetched.contentType ?? firstAttachment.contentType ?? undefined;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
runtime.error?.(
|
runtime.error?.(danger(`attachment fetch failed: ${String(err)}`));
|
||||||
danger(`signal: attachment fetch failed: ${String(err)}`),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,7 +398,7 @@ export async function monitorSignalProvider(
|
|||||||
abortSignal: opts.abortSignal,
|
abortSignal: opts.abortSignal,
|
||||||
onEvent: (event) => {
|
onEvent: (event) => {
|
||||||
void handleEvent(event).catch((err) => {
|
void handleEvent(event).catch((err) => {
|
||||||
runtime.error?.(`signal: event handler failed: ${String(err)}`);
|
runtime.error?.(`event handler failed: ${String(err)}`);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ describe("telegram inbound media", () => {
|
|||||||
expect(replySpy).not.toHaveBeenCalled();
|
expect(replySpy).not.toHaveBeenCalled();
|
||||||
expect(runtimeError).toHaveBeenCalledTimes(1);
|
expect(runtimeError).toHaveBeenCalledTimes(1);
|
||||||
const msg = String(runtimeError.mock.calls[0]?.[0] ?? "");
|
const msg = String(runtimeError.mock.calls[0]?.[0] ?? "");
|
||||||
expect(msg).toContain("Telegram handler failed:");
|
expect(msg).toContain("handler failed:");
|
||||||
expect(msg).toContain("file_path");
|
expect(msg).toContain("file_path");
|
||||||
|
|
||||||
fetchSpy.mockRestore();
|
fetchSpy.mockRestore();
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
|||||||
bot,
|
bot,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
runtime.error?.(danger(`Telegram handler failed: ${String(err)}`));
|
runtime.error?.(danger(`handler failed: ${String(err)}`));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ async function deliverReplies(params: {
|
|||||||
const { replies, chatId, runtime, bot } = params;
|
const { replies, chatId, runtime, bot } = params;
|
||||||
for (const reply of replies) {
|
for (const reply of replies) {
|
||||||
if (!reply?.text && !reply?.mediaUrl && !(reply?.mediaUrls?.length ?? 0)) {
|
if (!reply?.text && !reply?.mediaUrl && !(reply?.mediaUrls?.length ?? 0)) {
|
||||||
runtime.error?.(danger("Telegram reply missing text/media"));
|
runtime.error?.(danger("reply missing text/media"));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const mediaList = reply.mediaUrls?.length
|
const mediaList = reply.mediaUrls?.length
|
||||||
|
|||||||
@@ -46,9 +46,7 @@ export async function startTelegramWebhook(opts: {
|
|||||||
const handled = handler(req, res);
|
const handled = handler(req, res);
|
||||||
if (handled && typeof (handled as Promise<void>).catch === "function") {
|
if (handled && typeof (handled as Promise<void>).catch === "function") {
|
||||||
void (handled as Promise<void>).catch((err) => {
|
void (handled as Promise<void>).catch((err) => {
|
||||||
runtime.log?.(
|
runtime.log?.(`webhook handler failed: ${formatErrorMessage(err)}`);
|
||||||
`Telegram webhook handler failed: ${formatErrorMessage(err)}`,
|
|
||||||
);
|
|
||||||
if (!res.headersSent) res.writeHead(500);
|
if (!res.headersSent) res.writeHead(500);
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
@@ -64,7 +62,7 @@ export async function startTelegramWebhook(opts: {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await new Promise<void>((resolve) => server.listen(port, host, resolve));
|
await new Promise<void>((resolve) => server.listen(port, host, resolve));
|
||||||
runtime.log?.(`Telegram webhook listening on ${publicUrl}`);
|
runtime.log?.(`webhook listening on ${publicUrl}`);
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
server.close();
|
server.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user