[gjs] function: Print class name in error message
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] function: Print class name in error message
- Date: Mon, 23 Jan 2017 06:00:00 +0000 (UTC)
commit 421eed2f0885a16f790174b4e7eb4eac3fe14c6d
Author: Philip Chimento <philip chimento gmail com>
Date: Thu Jan 12 22:31:37 2017 -0800
function: Print class name in error message
If throwing an exception about too few arguments passed to a GI function,
and if the function is a message, then we should print the name of the
"container info" as well. That is, "Gio.File.read" rather than
"Gio.read".
https://bugzilla.gnome.org/show_bug.cgi?id=642506
gi/function.cpp | 24 +++++++++++++++++-------
installed-tests/js/testExceptions.js | 12 ++++++++++++
2 files changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index c38bbca..d061d74 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -745,13 +745,23 @@ gjs_invoke_c_function(JSContext *context,
*/
if (args.length() < function->expected_js_argc) {
- gjs_throw(context,
- "Too few arguments to %s %s.%s expected %d got %" G_GSIZE_FORMAT,
- is_method ? "method" : "function",
- g_base_info_get_namespace( (GIBaseInfo*) function->info),
- g_base_info_get_name( (GIBaseInfo*) function->info),
- function->expected_js_argc,
- args.length());
+ auto baseinfo = static_cast<GIBaseInfo *>(function->info);
+ if (is_method) {
+ gjs_throw(context, "Too few arguments to method %s.%s.%s: "
+ "expected %d, got %" G_GSIZE_FORMAT,
+ g_base_info_get_namespace(baseinfo),
+ g_base_info_get_name(g_base_info_get_container(baseinfo)),
+ g_base_info_get_name(baseinfo),
+ function->expected_js_argc,
+ args.length());
+ } else {
+ gjs_throw(context, "Too few arguments to function %s.%s: "
+ "expected %d, got %" G_GSIZE_FORMAT,
+ g_base_info_get_namespace(baseinfo),
+ g_base_info_get_name(baseinfo),
+ function->expected_js_argc,
+ args.length());
+ }
return false;
}
diff --git a/installed-tests/js/testExceptions.js b/installed-tests/js/testExceptions.js
index d5fcd4b..595682e 100644
--- a/installed-tests/js/testExceptions.js
+++ b/installed-tests/js/testExceptions.js
@@ -172,3 +172,15 @@ describe('logError', function () {
logError(new GLib.Error(GLib.quark_from_string('my-error'), 0, 'a message'), 'prefix');
});
});
+
+describe('Exception from function with too few arguments', function () {
+ it('contains the full function name', function () {
+ expect(() => GLib.get_locale_variants())
+ .toThrowError(/GLib\.get_locale_variants/);
+ });
+
+ it('contains the full method name', function () {
+ let file = Gio.File.new_for_path('foo');
+ expect(() => file.read()).toThrowError(/Gio\.File\.read/);
+ });
+});
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]