Discord-MusicBot icon indicating copy to clipboard operation
Discord-MusicBot copied to clipboard

error handling

Open Kief5555 opened this issue 3 years ago • 7 comments

Added error handling

Please describe the changes this PR makes and why it should be merged: Because its missing from the debug option

Status and versioning classification:

Added logging to errors and warning when DEBUG mode is enabled.

Kief5555 avatar Aug 06 '22 15:08 Kief5555

@SudhanPlayz fixed

Kief5555 avatar Aug 09 '22 00:08 Kief5555

I'm going to test this

JotaroKujo0525 avatar Aug 09 '22 02:08 JotaroKujo0525

Screenshot_20220809-181419 apparently, this commit still don't solve the issue with the error handling

JotaroKujo0525 avatar Aug 09 '22 10:08 JotaroKujo0525

Well, if It works for me it works for me. You are on a phone, on replit. Did you even try to produce a warning? All you showed is your console.

Kief5555 avatar Aug 09 '22 14:08 Kief5555

hello! i'm here to inform you that this error is rate limiting, there is no problem where you run the code. basically this is how it worked for you.

you waited long enough and the rate limit has been lifted so that's why you can login again

JotaroKujo0525 avatar Aug 09 '22 20:08 JotaroKujo0525

discord.js is not outputting error with this matter, so that's why it's kinda confusing in first not seeing your bot login, also the

process.on("warning")

is irrelevant since we're not using the --no-warnings and the warnings will be shown as usual

JotaroKujo0525 avatar Aug 09 '22 20:08 JotaroKujo0525

so tl;dr the current debug mode is already fine, there's some errors you can't see, and i thought this changes it but nah it still doesn't. in my experience with v5, debug mode is outputting the errors i need

JotaroKujo0525 avatar Aug 09 '22 20:08 JotaroKujo0525

so tl;dr the current debug mode is already fine, there's some errors you can't see, and i thought this changes it but nah it still doesn't. in my experience with v5, debug mode is outputting the errors i need

To be honest, you could just use a dedicated anticrash file for this which would be much more better for developers actively contributing to this project, tons of anticrash.js files are available on the internet and I've written my own below:

const chalk = require("chalk"); // Importing Chalk from Chalk
const { MessageEmbed, WebhookClient } = require('discord.js') // Importing MessageEmbed from Discord.js
const { inspect } = require("util");
const s = new WebhookClient({
                id: "id",
                token:"token",
            });
//not using normal client.channels.cache.get("id") functions as it returns bunch of errors.

module.exports = (client) => {

client.on('error', err => {
        // const a = client.channels.cache.get(config.ERROR_LOG_CHANNEL)
        console.log(err)
        const ErrorEmbed = new MessageEmbed()
            .setTitle('Error')
            .setURL('https://discordjs.guide/popular-topics/errors.html#api-errors')
            .setColor('#2F3136')
            .setDescription(`\`\`\`${inspect(error, {depth: 0})}\`\`\``)
            .setTimestamp()
        return s.send({
            embeds: [ErrorEmbed]
        })
    });

    process.on("unhandledRejection", (reason, p) => {
        console.log(
            chalk.yellow('[Anticrash] Unhandled Rejection\n'),
            reason, p
        )
        const unhandledRejectionEmbed = new MessageEmbed()
            .setTitle('**[Anticrash] Unhandled Rejection**')
            .setURL('https://nodejs.org/api/process.html#event-unhandledrejection')
            .setColor("#FF5555")
            .addField('Reason', `\`\`\`js\n${inspect(reason, { depth: 0 })}\`\`\``.substring(0, 1000))
            .addField('Promise', `\`\`\`js\n${inspect(p, { depth: 0 })}\`\`\``.substring(0, 1000))
            .setTimestamp()
        return s.send({
            embeds: [unhandledRejectionEmbed]
        })
    });
    
    process.on("uncaughtException", (err, origin) => {
        console.log(err, origin)
        const uncaughtExceptionEmbed = new MessageEmbed()
            .setTitle('**[Anticrash] Uncaught Exception**')
            .setColor("#FF5555")
            .setURL('https://nodejs.org/api/process.html#event-uncaughtexception')
            .addField('Error', `\`\`\`js\n${inspect(err, { depth: 0 })}\`\`\``.substring(0, 1000))
            .addField('Origin', `\`\`\`js\n${inspect(origin, { depth: 0 })}\`\`\``.substring(0, 1000))
            .setTimestamp()
        return s.send({
            embeds: [uncaughtExceptionEmbed]
        })
    });
    
    process.on("uncaughtExceptionMonitor", (err, origin) => {
        console.log(err, origin)
        const xd = new MessageEmbed()
            .setTitle('**[Anticrash] Uncaught Exception Monitor*')
            .setColor("#FF5555")
            .setURL('https://nodejs.org/api/process.html#event-uncaughtexceptionmonitor')
            .addField('Error', `\`\`\`js\n${inspect(err, { depth: 0 })}\`\`\``.substring(0, 1000))
            .addField('Origin', `\`\`\`js\n${inspect(origin, { depth: 0 })}\`\`\``.substring(0, 1000))
            .setTimestamp();
          return s.send({
            embeds: [xd]
        })
    });
    
    process.on("multipleResolves", (type, promise, reason) => {
        console.log(type, promise, reason)
        const multipleResolvesEmbed = new MessageEmbed()
            .setTitle('**[Anticrash] Multiple Resolves**')
            .setURL('https://nodejs.org/api/process.html#event-multipleresolves')
            .setColor("#FF5555")
            .addField('Type', `\`\`\`js\n${inspect(type, { depth: 0 })}\`\`\``.substring(0, 1000))
            .addField('Promise', `\`\`\`js\n${inspect(promise, { depth: 0 })}\`\`\``.substring(0, 1000))
            .addField('Reason', `\`\`\`js\n${inspect(reason, { depth: 0 })}\`\`\``.substring(0, 1000))
            .setTimestamp()
        return s.send({
            embeds: [multipleResolvesEmbed]
        })
    });
}

gspxrk avatar Aug 13 '22 17:08 gspxrk

so tl;dr the current debug mode is already fine, there's some errors you can't see, and i thought this changes it but nah it still doesn't. in my experience with v5, debug mode is outputting the errors i need

To be honest, you could just use a dedicated anticrash file for this which would be much more better for developers actively contributing to this project, tons of anticrash.js files are available on the internet and I've written my own below:

const chalk = require("chalk"); // Importing Chalk from Chalk
const { MessageEmbed, WebhookClient } = require('discord.js') // Importing MessageEmbed from Discord.js
const { inspect } = require("util");
const s = new WebhookClient({
                id: "id",
                token:"token",
            });
//not using normal client.channels.cache.get("id") functions as it returns bunch of errors.

module.exports = (client) => {

client.on('error', err => {
        // const a = client.channels.cache.get(config.ERROR_LOG_CHANNEL)
        console.log(err)
        const ErrorEmbed = new MessageEmbed()
            .setTitle('Error')
            .setURL('https://discordjs.guide/popular-topics/errors.html#api-errors')
            .setColor('#2F3136')
            .setDescription(`\`\`\`${inspect(error, {depth: 0})}\`\`\``)
            .setTimestamp()
        return s.send({
            embeds: [ErrorEmbed]
        })
    });

    process.on("unhandledRejection", (reason, p) => {
        console.log(
            chalk.yellow('[Anticrash] Unhandled Rejection\n'),
            reason, p
        )
        const unhandledRejectionEmbed = new MessageEmbed()
            .setTitle('**[Anticrash] Unhandled Rejection**')
            .setURL('https://nodejs.org/api/process.html#event-unhandledrejection')
            .setColor("#FF5555")
            .addField('Reason', `\`\`\`js\n${inspect(reason, { depth: 0 })}\`\`\``.substring(0, 1000))
            .addField('Promise', `\`\`\`js\n${inspect(p, { depth: 0 })}\`\`\``.substring(0, 1000))
            .setTimestamp()
        return s.send({
            embeds: [unhandledRejectionEmbed]
        })
    });
    
    process.on("uncaughtException", (err, origin) => {
        console.log(err, origin)
        const uncaughtExceptionEmbed = new MessageEmbed()
            .setTitle('**[Anticrash] Uncaught Exception**')
            .setColor("#FF5555")
            .setURL('https://nodejs.org/api/process.html#event-uncaughtexception')
            .addField('Error', `\`\`\`js\n${inspect(err, { depth: 0 })}\`\`\``.substring(0, 1000))
            .addField('Origin', `\`\`\`js\n${inspect(origin, { depth: 0 })}\`\`\``.substring(0, 1000))
            .setTimestamp()
        return s.send({
            embeds: [uncaughtExceptionEmbed]
        })
    });
    
    process.on("uncaughtExceptionMonitor", (err, origin) => {
        console.log(err, origin)
        const xd = new MessageEmbed()
            .setTitle('**[Anticrash] Uncaught Exception Monitor*')
            .setColor("#FF5555")
            .setURL('https://nodejs.org/api/process.html#event-uncaughtexceptionmonitor')
            .addField('Error', `\`\`\`js\n${inspect(err, { depth: 0 })}\`\`\``.substring(0, 1000))
            .addField('Origin', `\`\`\`js\n${inspect(origin, { depth: 0 })}\`\`\``.substring(0, 1000))
            .setTimestamp();
          return s.send({
            embeds: [xd]
        })
    });
    
    process.on("multipleResolves", (type, promise, reason) => {
        console.log(type, promise, reason)
        const multipleResolvesEmbed = new MessageEmbed()
            .setTitle('**[Anticrash] Multiple Resolves**')
            .setURL('https://nodejs.org/api/process.html#event-multipleresolves')
            .setColor("#FF5555")
            .addField('Type', `\`\`\`js\n${inspect(type, { depth: 0 })}\`\`\``.substring(0, 1000))
            .addField('Promise', `\`\`\`js\n${inspect(promise, { depth: 0 })}\`\`\``.substring(0, 1000))
            .addField('Reason', `\`\`\`js\n${inspect(reason, { depth: 0 })}\`\`\``.substring(0, 1000))
            .setTimestamp()
        return s.send({
            embeds: [multipleResolvesEmbed]
        })
    });
}

PS: You need to add: ``` js require("..events/anticrash") (client); in the index.js file!

gspxrk avatar Aug 13 '22 17:08 gspxrk

You know what, you guys keep arguing with me, disrespectful. Im not going to continue this pull request.

Kief5555 avatar Aug 13 '22 17:08 Kief5555

You know what, you guys keep arguing with me, disrespectful. Im not going to continue this pull request.

.... w h a t

gspxrk avatar Aug 13 '22 17:08 gspxrk

tf

JotaroKujo0525 avatar Aug 13 '22 23:08 JotaroKujo0525