From 88b2ec26c90c32d2ba29e2bebc98b781842ed166 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 3 Jun 2022 14:44:45 -0400 Subject: [PATCH] Adding some error handling --- functions.js | 20 ++++++++++++-------- main.js | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/functions.js b/functions.js index 09f0606..044d10a 100644 --- a/functions.js +++ b/functions.js @@ -27,14 +27,18 @@ const dotCommandFiles = fs.readdirSync('./dot-commands/').filter(file => file.en // MySQL database connection const mysql = require('mysql'); -const db = new mysql.createPool({ - connectionLimit: 10, - host: dbHost, - user: dbUser, - password: dbPass, - database: dbName, - port: dbPort, -}); +try { + const db = new mysql.createPool({ + connectionLimit: 10, + host: dbHost, + user: dbUser, + password: dbPass, + database: dbName, + port: dbPort, + }); +} catch (error) { + console.error(error); +} const functions = { // Functions for managing and creating Collections diff --git a/main.js b/main.js index 2dd9a0a..64dac9b 100644 --- a/main.js +++ b/main.js @@ -191,8 +191,14 @@ client.on('messageCreate', message => { if (lowerContent.includes('ligma')) message.reply('ligma balls, goteem'); // Break the message down into its components and analyze it - const commandData = fn.dot.getCommandData(message); - console.log(commandData); + try { + const commandData = fn.dot.getCommandData(message); + if(isDev) console.log(commandData); + } catch(error) { + console.error(error); + message.reply('There was an error trying to execute that command.'); + } + if (commandData.isValid && commandData.isCommand) { try { @@ -206,4 +212,9 @@ client.on('messageCreate', message => { return; }); +process.on("uncaughtException", err => { + console.error('There was an uncaught error: ', err); + process.exit(1); +}); + client.login(token); \ No newline at end of file