fix: log discord deploy error details

This commit is contained in:
Peter Steinberger
2026-01-24 11:09:47 +00:00
parent 298901208d
commit c42e9b1d19

View File

@@ -73,12 +73,39 @@ async function deployDiscordCommands(params: {
try {
await runWithRetry(() => params.client.handleDeployRequest(), "command deploy");
} catch (err) {
const details = formatDiscordDeployErrorDetails(err);
params.runtime.error?.(
danger(`discord: failed to deploy native commands: ${formatErrorMessage(err)}`),
danger(`discord: failed to deploy native commands: ${formatErrorMessage(err)}${details}`),
);
}
}
function formatDiscordDeployErrorDetails(err: unknown): string {
if (!err || typeof err !== "object") return "";
const status = (err as { status?: unknown }).status;
const discordCode = (err as { discordCode?: unknown }).discordCode;
const rawBody = (err as { rawBody?: unknown }).rawBody;
const details: string[] = [];
if (typeof status === "number") details.push(`status=${status}`);
if (typeof discordCode === "number" || typeof discordCode === "string") {
details.push(`code=${discordCode}`);
}
if (rawBody !== undefined) {
let bodyText = "";
try {
bodyText = JSON.stringify(rawBody);
} catch {
bodyText = String(rawBody);
}
if (bodyText) {
const maxLen = 800;
const trimmed = bodyText.length > maxLen ? `${bodyText.slice(0, maxLen)}...` : bodyText;
details.push(`body=${trimmed}`);
}
}
return details.length > 0 ? ` (${details.join(", ")})` : "";
}
export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
const cfg = opts.config ?? loadConfig();
const account = resolveDiscordAccount({