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 677513 - overrides/Gio: Provide an empty array on error, rather than null
overrides/Gio: Provide an empty array on error, rather than null
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: Philip Chimento
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2012-06-05 21:18 UTC by Jasper St. Pierre (not reading bugmail)
Modified: 2017-02-16 04:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
overrides/Gio: Provide an empty array on error, rather than null (1.14 KB, patch)
2012-06-05 21:18 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review
overrides/Gio: Provide an empty array on error, rather than null (3.21 KB, patch)
2017-01-06 05:26 UTC, Philip Chimento
committed Details | Review

Description Jasper St. Pierre (not reading bugmail) 2012-06-05 21:18:11 UTC
See patch. This fixes errors like:

    JS ERROR: !!!   Exception was: TypeError: arguments[0] is null
    JS ERROR: !!!     lineNumber = '274'
    JS ERROR: !!!     fileName = '"/home/jstpierre/Source/gnome3/source/gnome-shell/js/ui/calendar.js"'
    JS ERROR: !!!     stack = '"(null,[object Error])@/home/jstpierre/Source/gnome3/source/gnome-shell/js/ui/calendar.js:274
wrapper(null,[object Error])@/home/jstpierre/Source/gnome3/install/share/gjs-1.0/lang.js:204
([object _private_Gio_DBusProxy],[object _private_Gio_SimpleAsyncResult])@/home/jstpierre/Source/gnome3/install/share/gjs-1.0/overrides/Gio.js:88
"'

when opening the gnome-shell calendar with Matthew's patch.
Comment 1 Jasper St. Pierre (not reading bugmail) 2012-06-05 21:18:12 UTC
Created attachment 215690 [details] [review]
overrides/Gio: Provide an empty array on error, rather than null

Gio is often used with destructuring assignment:

    proxy.ThingRemote(1, 2, 3, function([a, b, c], e) {
        log([a, b, c]);
    });

If, on error, we provide null instead of an array, we'll crash as
the runtime tries to iterate over null. As DBus return values are
guaranteed to be tuples, this is always a safe choice.
Comment 2 Colin Walters 2012-06-05 21:23:16 UTC
Review of attachment 215690 [details] [review]:

This is an incompatible change; it will break code that was checking for null on error.

It looks like then we'd assign "undefined" to the variables, so code that wanted to handle it would then have to check "if (a === undefined)" which really isn't better.  Most code would equally well crash on undefined too.

I don't think this change is going to actually help much.  If code isn't handling errors, then it needs to be fixed.  Checking for null before destructuring is really just as easy as checking for undefined.  Right?
Comment 3 Jasper St. Pierre (not reading bugmail) 2012-06-05 21:35:01 UTC
Review of attachment 215690 [details] [review]:

The correct fix is to check if error !== null.

Also, the problem is when there's destructuring assignment in the function signature. We can't really run code before the function call initialization.
Comment 4 Jasper St. Pierre (not reading bugmail) 2012-06-06 04:29:16 UTC
So, we had a lengthy discussion about this earlier today.

This is an API break technically, as programs could be incorrectly checking for "if (result)" or "if (result == null)" instead of "if (error)" or some variant.

By the end we decided that the current "pass the error to the caller and let them drop it on the floor" approach is a bad API to allow error handling.

Given that Giovanni is currently working on a new set of GDBus overrides, it's possible we could fix this when that lands, remove the old set, and hopefully ditch imports.dbus as well.

Gio.AsyncResult gets around this by turning it into a pair of calls, which means that you can effectively throw an error from that second "get result" call.
Comment 5 Philip Chimento 2017-01-06 05:26:23 UTC
Created attachment 343001 [details] [review]
overrides/Gio: Provide an empty array on error, rather than null

Gio is often used with destructuring assignment:

    proxy.ThingRemote(1, 2, 3, function([a, b, c], e) {
        log([a, b, c]);
    });

If, on error, we provide null instead of an array, we'll crash as
the runtime tries to iterate over null. As DBus return values are
guaranteed to be tuples, this is always a safe choice.

This is a backwards-incompatible change, since client code may have been
checking for a null result on error. Original patch by Jasper St. Pierre,
rebased and test added by Philip Chimento.
Comment 6 Philip Chimento 2017-01-06 05:29:17 UTC
Here's a rebased patch with a test added.

I'm ambivalent about committing this. It's a pity that it didn't get fixed in Giovanni's new GDBus overrides... but I agree that client code checking for result === null should have been checking for error !== null.
Comment 7 Cosimo Cecchi 2017-02-15 18:10:15 UTC
Review of attachment 343001 [details] [review]:

I think this makes sense; I would like to take a chance to push it this cycle, since we already have made some changes that affect corner cases.
But I could be convinced that it's too late in the cycle; are you aware of any clients that rely on the incorrect behavior?
Comment 8 Philip Chimento 2017-02-16 04:28:44 UTC
I don't know of any clients that rely on the incorrect behaviour, but then again it would be really difficult to search for it. Let's push it, I agree with your reasoning and I think it's a change that polishes down a rough edge.
Comment 9 Philip Chimento 2017-02-16 04:52:39 UTC
Attachment 343001 [details] pushed as 9c37b55 - overrides/Gio: Provide an empty array on error, rather than null