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) => {
log(new Error("Unhandled Rejection:"), reason, promise);
let message: string | Error;
let message: string;
if (reason instanceof Error) {
message = reason;
} else if (typeof reason == "string") {
message = reason;
message = `${reason.name}: ${reason.message}\n${reason.stack}`;
} else {
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);
});
process.on("uncaughtException", (err) => {
log(new Error("Uncaught Exception:"), err);
log(new Error("Uncaught Exception in app:"), err);
let message: string | Error;
if (err instanceof Error) {
message = err;
} else if (typeof err == "string") {
message = err;
} else {
message = String(err);
}

View File

@ -113,8 +113,12 @@ export function log(...content: unknown[]) {
}
export async function sendDM(user: User, txt: string) {
await sendWithoutReply(await user.createDM(), txt)
.catch(() => log(new Error(`dementovi ${user} nejde poslat DM ${txt}`)));
try {
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);
@ -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 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({
channelId: channelId,
guildId,
//@ts-ignore PIČOVINA ZASRATA!"!"!"!"!"!"!""""
adapterCreator: guild.voiceAdapterCreator
});