Hopefully improve error reporting

This commit is contained in:
Histmy 2025-10-15 13:53:25 +02:00
parent 81526839cb
commit bfccc0eac9
3 changed files with 18 additions and 13 deletions

View File

@ -30,29 +30,31 @@ client.on("shardError", err => {
}); });
process.on("unhandledRejection", (reason, promise) => { process.on("unhandledRejection", (reason, promise) => {
log(new Error("Unhandled Rejection:"), reason, promise); let message: string;
let message: string | Error;
if (reason instanceof Error) { if (reason instanceof Error) {
message = reason; message = `${reason.name}: ${reason.message}\n${reason.stack}`;
} else if (typeof reason == "string") {
message = reason;
} else { } else {
message = String(reason); message = String(reason);
} }
if (message.includes("Connect Timeout Error") && message.includes("10000ms")) {
// Klasika
log(new Error("Discord timeout..."));
return;
}
log(new Error("Unhandled Rejection in app:"), reason, promise);
adminLog(client, "Unhandled Rejection", message); adminLog(client, "Unhandled Rejection", message);
}); });
process.on("uncaughtException", (err) => { process.on("uncaughtException", (err) => {
log(new Error("Uncaught Exception:"), err); log(new Error("Uncaught Exception in app:"), err);
let message: string | Error; let message: string | Error;
if (err instanceof Error) { if (err instanceof Error) {
message = err; message = err;
} else if (typeof err == "string") {
message = err;
} else { } else {
message = String(err); message = String(err);
} }

View File

@ -113,8 +113,12 @@ export function log(...content: unknown[]) {
} }
export async function sendDM(user: User, txt: string) { export async function sendDM(user: User, txt: string) {
await sendWithoutReply(await user.createDM(), txt) try {
.catch(() => log(new Error(`dementovi ${user} nejde poslat DM ${txt}`))); const channel = await user.createDM();
await sendWithoutReply(channel, txt);
} catch (e) {
log(new Error(`dementovi ${user} nejde poslat DM ${txt}`));
}
} }
export const rand = (max: number) => Math.floor(Math.random() * max); export const rand = (max: number) => Math.floor(Math.random() * max);
@ -257,7 +261,7 @@ export async function messageReply(mes: SMessage, co: string | MessageCreateOpti
} }
/** /**
* Slouží k odeslání zprávy bez odpovědi na jinou zprávu a zajistí, anti-spam mechanismus bude fungovat. * Slouží k odeslání zprávy bez odpovědi na jinou zprávu a zajistí, že anti-spam mechanismus bude fungovat.
* @param channel Kanál, kam se zpráva odeslat * @param channel Kanál, kam se zpráva odeslat
* @param co Obsah zprávy, který se odeslat * @param co Obsah zprávy, který se odeslat
*/ */

View File

@ -72,7 +72,6 @@ export const novejJoin = (guild: Guild, channelId: string) => new Promise<boolea
const conn = joinVoiceChannel({ const conn = joinVoiceChannel({
channelId: channelId, channelId: channelId,
guildId, guildId,
//@ts-ignore PIČOVINA ZASRATA!"!"!"!"!"!"!""""
adapterCreator: guild.voiceAdapterCreator adapterCreator: guild.voiceAdapterCreator
}); });