From 1b2ea3c6bf64650d94fa93da23f22887d7742d2a Mon Sep 17 00:00:00 2001 From: jackb-p Date: Thu, 4 Aug 2016 18:16:09 +0100 Subject: [PATCH] Add runtime error checking for custom JS --- TriviaBot/bot/APIHelper.cpp | 4 ++++ TriviaBot/bot/js/CommandHelper.cpp | 2 +- TriviaBot/bot/js/V8Instance.cpp | 29 ++++++++++++++++++++++------- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/TriviaBot/bot/APIHelper.cpp b/TriviaBot/bot/APIHelper.cpp index 2e8fd03..5df8e88 100644 --- a/TriviaBot/bot/APIHelper.cpp +++ b/TriviaBot/bot/APIHelper.cpp @@ -15,6 +15,10 @@ APIHelper::APIHelper() : BASE_URL("https://discordapp.com/api"), CHANNELS_URL(BA } void APIHelper::send_message(std::string channel_id, std::string message) { + if (message == "") { + Logger::write("[send_message] Tried to send empty message", Logger::LogLevel::Warning); + } + const std::string url = CHANNELS_URL + "/" + channel_id + "/messages"; json data = { { "content", message } diff --git a/TriviaBot/bot/js/CommandHelper.cpp b/TriviaBot/bot/js/CommandHelper.cpp index d641f8b..4722632 100644 --- a/TriviaBot/bot/js/CommandHelper.cpp +++ b/TriviaBot/bot/js/CommandHelper.cpp @@ -34,7 +34,7 @@ CommandHelper::CommandHelper() { } } - Logger::write(std::to_string(commands.size()) + " custom command loaded", Logger::LogLevel::Info); + Logger::write(std::to_string(commands.size()) + " custom command(s) loaded", Logger::LogLevel::Info); sqlite3_finalize(stmt); sqlite3_close(db); diff --git a/TriviaBot/bot/js/V8Instance.cpp b/TriviaBot/bot/js/V8Instance.cpp index a8fd3f0..78ba8cf 100644 --- a/TriviaBot/bot/js/V8Instance.cpp +++ b/TriviaBot/bot/js/V8Instance.cpp @@ -67,22 +67,37 @@ void V8Instance::exec_js(std::string js, std::string channel_id) { // compile Logger::write("[v8] Isolate nullptr? " + std::to_string(isolate == nullptr) + " Context empty? " + std::to_string(context.IsEmpty()), Logger::LogLevel::Debug); - TryCatch try_catch(isolate); + TryCatch compile_try_catch(isolate); Local