From 61dfe2de65f4afa067eb37b2a24b8d73448972a1 Mon Sep 17 00:00:00 2001 From: ferricles Date: Fri, 24 Jun 2022 21:01:54 -0700 Subject: [PATCH] assert error --- js/utils.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/js/utils.js b/js/utils.js index a14afff..f3352fd 100644 --- a/js/utils.js +++ b/js/utils.js @@ -510,3 +510,16 @@ function assert_null(arg, msg) { } } +/** Asserts that there is an error when a callback function is run. + * + * @param {Function} func_binding - a function binding to run. Can be passed in with func.bind(null, arg1, ..., argn) + * @param {String} msg - the error message to throw. + */ +function assert_error(func_binding, msg) { + try { + func_binding(); + console.trace(msg ? msg : "Function didn't throw an error."); + } catch (err) { + return; + } +}