After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 690984 - Gjs messages are hard to parse
Gjs messages are hard to parse
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
1.35.x
Other Linux
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
: 695718 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2013-01-02 05:36 UTC by lamefun
Modified: 2013-05-07 15:56 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Use GLib for JS logging (48.12 KB, patch)
2013-01-02 21:52 UTC, Giovanni Campagna
needs-work Details | Review
Fix cairo test (926 bytes, patch)
2013-05-07 11:32 UTC, Giovanni Campagna
committed Details | Review
Fix JSUnit to use regular exceptions objects (3.13 KB, patch)
2013-05-07 11:32 UTC, Giovanni Campagna
committed Details | Review
Use GLib for JS logging (41.40 KB, patch)
2013-05-07 11:32 UTC, Giovanni Campagna
committed Details | Review
Stop walking the stack manually (12.62 KB, patch)
2013-05-07 11:33 UTC, Giovanni Campagna
reviewed Details | Review
Stop walking the stack manually (12.57 KB, patch)
2013-05-07 15:48 UTC, Giovanni Campagna
committed Details | Review

Description lamefun 2013-01-02 05:36:27 UTC
The current output is:

    JS ERROR: !!!   Exception was: ReferenceError: ddd is not defined
    JS ERROR: !!!     message = '"ddd is not defined"'
    JS ERROR: !!!     fileName = '"/home/lamefun/test/share/glicket/src/textView.js"'
    JS ERROR: !!!     lineNumber = '32'
    JS ERROR: !!!     stack = '"()@/home/lamefun/test/share/glicket/src/textView.js:32
wrapper()@/usr/share/gjs-1.0/lang.js:204
_parent((void 0))@/usr/share/gjs-1.0/lang.js:166
()@/home/lamefun/test/share/glicket/src/textView.js:13
wrapper()@/usr/share/gjs-1.0/lang.js:204
()@/home/lamefun/test/share/glicket/src/mainView.js:119
wrapper()@/usr/share/gjs-1.0/lang.js:204
()@/home/lamefun/test/share/glicket/src/main.js:100
wrapper()@/usr/share/gjs-1.0/lang.js:204
()@/home/lamefun/test/share/glicket/src/main.js:35
wrapper()@/usr/share/gjs-1.0/lang.js:204
start([object Array])@/home/lamefun/test/share/glicket/src/main.js:146
@<command line>:1
"'

It isn't really clear where it starts and ends. The messages should be easier to parse.
Comment 1 Giovanni Campagna 2013-01-02 21:52:24 UTC
Created attachment 232585 [details] [review]
Use GLib for JS logging

Reserve our custom logging framework for debug logging, and use standard
g_log functions for log() and logError().
This allows us to finally have readable error messages, it associates
them with a program and process when necessary, and it prepares us
for a future where glib logs to the journal by default.

This is something I wanted to do for a looong time!
Comment 2 Jasper St. Pierre (not reading bugmail) 2013-01-02 22:08:44 UTC
Review of attachment 232585 [details] [review]:

And I'm glad you found a vaguely related bug to do so!

::: gjs/jsapi-util.c
@@ +619,3 @@
     props_iter = JS_NewPropertyIterator(context, obj);
     if (props_iter == NULL) {
+        gjs_log_exception(context);

Seems like a bad translation?

@@ -728,3 @@
-void
-gjs_log_exception_props(JSContext *context,
-                        jsval      exc)

Could you take the changes you've made to this file that are separable and put them in their own patch, and then file a new bug for the rest of the changes?

This isn't about GLib warnings vs. our own warnings framework, it's about good warnings vs. absurdly silly warnings.

@@ +740,3 @@
+    if (utf8_message) {
+        if (utf8_stack)
+            g_warning("JS ERROR: %s: %s\n%s", utf8_message, utf8_exception, utf8_stack);

Not sure this is any better, bub.

Also, isn't there some GNU printf extension that allows conditional things, which would allow us to emit that colon only if utf8_message is truthy.

::: modules/jsUnit.js
@@ +372,3 @@
   top.xbDebugTraceFunction('top.testManager.containerTestFrame', 'warn');
   top.xbDebugTraceFunction('top.testManager.containerTestFrame', 'inform');
   top.xbDebugTraceFunction('top.testManager.containerTestFrame', 'debug');

Unrelated changes to this file?

::: test/js/testCairo.js
@@ +172,3 @@
     o.connect('sig-with-foreign-struct', function(o, cr) {
         called = true;
+        assertEquals(_ts(cr), "CairoContext");

Unrelated.
Comment 3 Giovanni Campagna 2013-01-02 22:17:31 UTC
(In reply to comment #2)
> Review of attachment 232585 [details] [review]:
> 
> And I'm glad you found a vaguely related bug to do so!
> 
> ::: gjs/jsapi-util.c
> @@ +619,3 @@
>      props_iter = JS_NewPropertyIterator(context, obj);
>      if (props_iter == NULL) {
> +        gjs_log_exception(context);
> 
> Seems like a bad translation?

Possibly. But a full exception message seems more useful than a generic failure message.

> @@ -728,3 @@
> -void
> -gjs_log_exception_props(JSContext *context,
> -                        jsval      exc)
> 
> Could you take the changes you've made to this file that are separable and put
> them in their own patch, and then file a new bug for the rest of the changes?
> 
> This isn't about GLib warnings vs. our own warnings framework, it's about good
> warnings vs. absurdly silly warnings.

Except they're not really separable. If I call gjs_debug(GJS_DEBUG_ERROR...) with the new strings I get

    JS ERROR: !!!   ReferenceError: ddd is not defined
    JS ERROR: !!!   @/home/lamefun/test/share/glicket/src/textView.js:32
wrapper()@/usr/share/gjs-1.0/lang.js:204
_parent((void 0))@/usr/share/gjs-1.0/lang.js:166
()@/home/lamefun/test/share/glicket/src/textView.js:13
wrapper()@/usr/share/gjs-1.0/lang.js:204
()@/home/lamefun/test/share/glicket/src/mainView.js:119
wrapper()@/usr/share/gjs-1.0/lang.js:204
()@/home/lamefun/test/share/glicket/src/main.js:100
wrapper()@/usr/share/gjs-1.0/lang.js:204
()@/home/lamefun/test/share/glicket/src/main.js:35
wrapper()@/usr/share/gjs-1.0/lang.js:204
start([object Array])@/home/lamefun/test/share/glicket/src/main.js:146
@<command line>:1

which is not a big improvement...

(compare to:

(gnome-shell-real:15894): Gjs-WARNING **: JS ERROR: Error: an error
@/opt/gnome/share/gnome-shell/js/ui/lookingGlass.js:1051
("logError(Error('an error'))")@/opt/gnome/share/gnome-shell/js/ui/lookingGlass.js:1051
wrapper("logError(Error('an error'))")@/opt/gnome/share/gjs-1.0/lang.js:204
([object GObject_Object])@/opt/gnome/share/gnome-shell/js/ui/lookingGlass.js:930

)

> @@ +740,3 @@
> +    if (utf8_message) {
> +        if (utf8_stack)
> +            g_warning("JS ERROR: %s: %s\n%s", utf8_message, utf8_exception,
> utf8_stack);
> 
> Not sure this is any better, bub.
> 
> Also, isn't there some GNU printf extension that allows conditional things,
> which would allow us to emit that colon only if utf8_message is truthy.

I guess 

> ::: modules/jsUnit.js
> @@ +372,3 @@
>    top.xbDebugTraceFunction('top.testManager.containerTestFrame', 'warn');
>    top.xbDebugTraceFunction('top.testManager.containerTestFrame', 'inform');
>    top.xbDebugTraceFunction('top.testManager.containerTestFrame', 'debug');
> 
> Unrelated changes to this file?

Not really. The new exception logger assumes that exception stringify to something useful and have 'stack' property which is a string. Errors from the JS unit test framework had neither of these properties.

> ::: test/js/testCairo.js
> @@ +172,3 @@
>      o.connect('sig-with-foreign-struct', function(o, cr) {
>          called = true;
> +        assertEquals(_ts(cr), "CairoContext");
> 
> Unrelated.

Except that without the fix, the test suite doesn't run, because GLib warnings are fatal inside gtester.
Comment 4 Jasper St. Pierre (not reading bugmail) 2013-01-02 22:22:21 UTC
(In reply to comment #3)
> Except they're not really separable. If I call gjs_debug(GJS_DEBUG_ERROR...)
> with the new strings I get
> 
>     JS ERROR: !!!   ReferenceError: ddd is not defined
>     JS ERROR: !!!   @/home/lamefun/test/share/glicket/src/textView.js:32
> wrapper()@/usr/share/gjs-1.0/lang.js:204
> _parent((void 0))@/usr/share/gjs-1.0/lang.js:166
> ()@/home/lamefun/test/share/glicket/src/textView.js:13
> wrapper()@/usr/share/gjs-1.0/lang.js:204
> ()@/home/lamefun/test/share/glicket/src/mainView.js:119
> wrapper()@/usr/share/gjs-1.0/lang.js:204
> ()@/home/lamefun/test/share/glicket/src/main.js:100
> wrapper()@/usr/share/gjs-1.0/lang.js:204
> ()@/home/lamefun/test/share/glicket/src/main.js:35
> wrapper()@/usr/share/gjs-1.0/lang.js:204
> start([object Array])@/home/lamefun/test/share/glicket/src/main.js:146
> @<command line>:1
> 
> which is not a big improvement...

I think it is.

> (compare to:
> 
> (gnome-shell-real:15894): Gjs-WARNING **: JS ERROR: Error: an error
> @/opt/gnome/share/gnome-shell/js/ui/lookingGlass.js:1051
> ("logError(Error('an
> error'))")@/opt/gnome/share/gnome-shell/js/ui/lookingGlass.js:1051
> wrapper("logError(Error('an error'))")@/opt/gnome/share/gjs-1.0/lang.js:204
> ([object
> GObject_Object])@/opt/gnome/share/gnome-shell/js/ui/lookingGlass.js:930
> 
> )

The only thing different is the prefix. Well, besides the two different stack traces.

> > ::: modules/jsUnit.js
> > @@ +372,3 @@
> >    top.xbDebugTraceFunction('top.testManager.containerTestFrame', 'warn');
> >    top.xbDebugTraceFunction('top.testManager.containerTestFrame', 'inform');
> >    top.xbDebugTraceFunction('top.testManager.containerTestFrame', 'debug');
> > 
> > Unrelated changes to this file?
> 
> Not really. The new exception logger assumes that exception stringify to
> something useful and have 'stack' property which is a string. Errors from the
> JS unit test framework had neither of these properties.

Well, land these changes first.

> > ::: test/js/testCairo.js
> > @@ +172,3 @@
> >      o.connect('sig-with-foreign-struct', function(o, cr) {
> >          called = true;
> > +        assertEquals(_ts(cr), "CairoContext");
> > 
> > Unrelated.
> 
> Except that without the fix, the test suite doesn't run, because GLib warnings
> are fatal inside gtester.

Yeah, this is an obvious bug. It deserves to have its own patch, not grouped in with random other changes.
Comment 5 Giovanni Campagna 2013-05-07 11:32:49 UTC
Created attachment 243469 [details] [review]
Fix cairo test

We should check for equality, not truthiness.
Comment 6 Giovanni Campagna 2013-05-07 11:32:54 UTC
Created attachment 243470 [details] [review]
Fix JSUnit to use regular exceptions objects

This way we can assume that all exceptions stringify to something
useful and have a valid .stack property, which is an assumption
we want to make for the new error logger.
Comment 7 Giovanni Campagna 2013-05-07 11:32:59 UTC
Created attachment 243471 [details] [review]
Use GLib for JS logging

Reserve our custom logging framework for debug logging, and use standard
g_log functions for log() and logError().
This allows us to finally have readable error messages, it associates
them with a program and process when necessary, and it prepares us
for a future where glib logs to the journal by default.
Comment 8 Giovanni Campagna 2013-05-07 11:33:04 UTC
Created attachment 243472 [details] [review]
Stop walking the stack manually

In JS 17, and when dealing with optimized frames without "arguments",
our technique to build the stack can fail and throw an exception.
Normally we would override it when we set the real exception, but
in the GDBus test suite we didn't, so there was always this
unnoticed "Debugger scope is not live" error, until it was made
fatal by glib changes.
Comment 9 Jasper St. Pierre (not reading bugmail) 2013-05-07 15:31:40 UTC
Review of attachment 243469 [details] [review]:

OK.
Comment 10 Jasper St. Pierre (not reading bugmail) 2013-05-07 15:32:53 UTC
Review of attachment 243470 [details] [review]:

OK.
Comment 11 Jasper St. Pierre (not reading bugmail) 2013-05-07 15:35:20 UTC
Review of attachment 243471 [details] [review]:

OK.
Comment 12 Jasper St. Pierre (not reading bugmail) 2013-05-07 15:37:26 UTC
Review of attachment 243472 [details] [review]:

::: gjs/stack.c
@@ +60,3 @@
+                        "Error", &v_constructor) ||
+        !JSVAL_IS_OBJECT(v_constructor)) {
+        JS_ReportError(context, "??? Missing Error constructor in global object?");

g_error. This is absolutely fatal.

@@ +64,3 @@
     }
 
+    /* throw new Error(message) */

"new Error(null)"
Comment 13 Giovanni Campagna 2013-05-07 15:39:39 UTC
(In reply to comment #12)
> Review of attachment 243472 [details] [review]:
> 
> ::: gjs/stack.c
> @@ +60,3 @@
> +                        "Error", &v_constructor) ||
> +        !JSVAL_IS_OBJECT(v_constructor)) {
> +        JS_ReportError(context, "??? Missing Error constructor in global
> object?");
> 
> g_error. This is absolutely fatal.

I just copy-pasted from gjs_throw, but ok.
Comment 14 Jasper St. Pierre (not reading bugmail) 2013-05-07 15:39:53 UTC
*** Bug 695718 has been marked as a duplicate of this bug. ***
Comment 15 Giovanni Campagna 2013-05-07 15:48:13 UTC
Created attachment 243501 [details] [review]
Stop walking the stack manually

In JS 17, and when dealing with optimized frames without "arguments",
our technique to build the stack can fail and throw an exception.
Normally we would override it when we set the real exception, but
in the GDBus test suite we didn't, so there was always this
unnoticed "Debugger scope is not live" error, until it was made
fatal by glib changes.
Comment 16 Jasper St. Pierre (not reading bugmail) 2013-05-07 15:49:20 UTC
Review of attachment 243501 [details] [review]:

::: gjs/stack.c
@@ +64,3 @@
     }
 
+    err_obj = JS_New(context, JSVAL_TO_OBJECT(v_constructor), 0, NULL);

Erm, you didn't have to remove the comment entirely.
Comment 17 Giovanni Campagna 2013-05-07 15:56:20 UTC
Attachment 243469 [details] pushed as 8adde7c - Fix cairo test
Attachment 243470 [details] pushed as 61d3d45 - Fix JSUnit to use regular exceptions objects
Attachment 243471 [details] pushed as 9deaf85 - Use GLib for JS logging
Attachment 243501 [details] pushed as 6cdf959 - Stop walking the stack manually