From bd766297efb5a8e662dddb5cbe07c08a78dc33e6 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Thu, 18 Feb 2016 12:50:44 -0800 Subject: [PATCH] Improve error message in sorted() method --- src/js_results.cpp | 2 +- src/js_util.hpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/js_results.cpp b/src/js_results.cpp index 37f9e95e..a14f420c 100644 --- a/src/js_results.cpp +++ b/src/js_results.cpp @@ -101,7 +101,7 @@ JSValueRef ResultsSorted(JSContextRef ctx, JSObjectRef function, JSObjectRef thi std::vector ascending; if (RJSIsValueArray(ctx, arguments[0])) { - RJSValidateArgumentCount(argumentCount, 1); + RJSValidateArgumentCount(argumentCount, 1, "Second argument is not allowed if passed an array of sort descriptors"); JSObjectRef js_prop_names = RJSValidatedValueToObject(ctx, arguments[0]); prop_count = RJSValidatedListLength(ctx, js_prop_names); diff --git a/src/js_util.hpp b/src/js_util.hpp index 95886940..cd292025 100644 --- a/src/js_util.hpp +++ b/src/js_util.hpp @@ -58,21 +58,21 @@ std::string RJSValidatedStringForValue(JSContextRef ctx, JSValueRef value, const JSStringRef RJSStringForString(const std::string &str); JSValueRef RJSValueForString(JSContextRef ctx, const std::string &str); -inline void RJSValidateArgumentCount(size_t argumentCount, size_t expected) { +inline void RJSValidateArgumentCount(size_t argumentCount, size_t expected, const char *message = NULL) { if (argumentCount != expected) { - throw std::invalid_argument("Invalid arguments"); + throw std::invalid_argument(message ?: "Invalid arguments"); } } -inline void RJSValidateArgumentCountIsAtLeast(size_t argumentCount, size_t expected) { +inline void RJSValidateArgumentCountIsAtLeast(size_t argumentCount, size_t expected, const char *message = NULL) { if (argumentCount < expected) { - throw std::invalid_argument("Invalid arguments"); + throw std::invalid_argument(message ?: "Invalid arguments"); } } -inline void RJSValidateArgumentRange(size_t argumentCount, size_t min, size_t max) { +inline void RJSValidateArgumentRange(size_t argumentCount, size_t min, size_t max, const char *message = NULL) { if (argumentCount < min || argumentCount > max) { - throw std::invalid_argument("Invalid arguments"); + throw std::invalid_argument(message ?: "Invalid arguments"); } }