Uncaught Error: Session.call: <args> must be an array []

121 views
Skip to first unread message

Scott Reed

unread,
Aug 22, 2014, 4:33:55 PM8/22/14
to autob...@googlegroups.com
I am trying to implement RPC using AutobahnJs 0.8.10 on OSX 10.9.4 with node-webkit 0.8.6 and getting an error when the app makes a call: "Uncaught Error: Session.call: <args> must be an array []". I'm definitely passing in an array but the assertion is failing. When I comment out the assert that's issuing the error the rpcs work okay.

I am also seeing a case where a string gets corrupted (English characters -> Chinese) when passed to the callee. How do I prevent that?

Any help would be greatly appreciated.
  Thanks,
     Scott

Scott Reed

unread,
Aug 22, 2014, 4:59:22 PM8/22/14
to autob...@googlegroups.com
I forgot to mention that the corrupted string is one of three in the array being passed and only one of them is affected.

Alexander Gödde

unread,
Aug 23, 2014, 9:38:33 AM8/23/14
to autob...@googlegroups.com
Hi!

In order for us to take a look at this, we need some more information, especially since we haven't worked with node-webkit.

- How are you using Autobahn|JS in node-webkit - does this work via npm or loaded from a file?

- What's your code that sends the RPC? What are the arguments?

- If the browser dev tools are available in node-webkit, could you take a look a the 'network' tab, click on the websocket connection there, and send us the frames in question?

Once we have more information, we'll be happy to look into the issue.

Regards,

Alex


--
You received this message because you are subscribed to the Google Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autobahnws+...@googlegroups.com.
To post to this group, send email to autob...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/5af0b533-d6b7-4e9b-8920-f4a1e2e6bb94%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Scott Reed

unread,
Aug 23, 2014, 6:39:16 PM8/23/14
to autob...@googlegroups.com
I'm using npm: 
var autobahn = require('autobahn');
The code is:
var args = [i, d.chart_type, d.region_type, category];
session.call("x.select", args);
There are no frames because the call fails because the second assert fails: 
Session.prototype.call = function (procedure, args, kwargs, options) {
   util.assert(typeof procedure === 'string', "Session.call: <procedure> must be a string");
   util.assert(!args || args instanceof Array, "Session.call: <args> must be an array []");
   util.assert(!kwargs || kwargs instanceof Object, "Session.call: <kwargs> must be an object {}");
   util.assert(!options || options instanceof Object, "Session.call: <options> must be an object {}");
If I comment out the highlighted line it works fine.
 

Tobias Oberstein

unread,
Aug 24, 2014, 2:59:44 AM8/24/14
to autob...@googlegroups.com
Am 24.08.2014 00:39, schrieb Scott Reed:
> I'm using npm:
>
> var autobahn = require('autobahn');

I guess this means you are using the NodeJS variant of AutobahnJS, not
the browser variant. I have zero experience with node-webkit.


What AutobahnJS version? What does

autobahn.version;

tell?

>
> The code is:
>
> var args = [i, d.chart_type, d.region_type, category];

Can you add

console.log(args instanceof Array);

right after above line and tell us what that outputs?

What do you get with the following?

$ node --version
v0.10.24
$ node
> [1,2,3] instanceof Array
true
> Array
[Function: Array]

> session.call("x.select", args);
>
> There are no frames because the call fails because the second assert fails:
>
> Session.prototype.call = function (procedure, args, kwargs, options) {
> util.assert(typeof procedure === 'string', "Session.call:
> <procedure> must be a string");
> util.assert(!args || args instanceof Array, "Session.call: <args>
> must be an array []");
> util.assert(!kwargs || kwargs instanceof Object, "Session.call:
> <kwargs> must be an object {}");
> util.assert(!options || options instanceof Object,
> "Session.call: <options> must be an object {}");
>
> If I comment out the highlighted line it works fine.

The assert works fine in browsers and (pure) node apps. We can't remove
that.

>
> --
> You received this message because you are subscribed to the Google
> Groups "Autobahn" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to autobahnws+...@googlegroups.com
> <mailto:autobahnws+...@googlegroups.com>.
> To post to this group, send email to autob...@googlegroups.com
> <mailto:autob...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autobahnws/cae94395-2a25-499b-9493-29c6c43ebfcd%40googlegroups.com
> <https://groups.google.com/d/msgid/autobahnws/cae94395-2a25-499b-9493-29c6c43ebfcd%40googlegroups.com?utm_medium=email&utm_source=footer>.

Scott Reed

unread,
Aug 24, 2014, 1:23:51 PM8/24/14
to autob...@googlegroups.com
I agree that you should not remove the assert but you can change it to be more compatible with variations of JS. I found that the following works with my version of node-webkit:
Session.prototype.call = function (procedure, args, kwargs, options) {
   util.assert(typeof procedure === 'string', "Session.call: <procedure> must be a string");
   util.assert(!args ||  Array.isArray(args) /*args instanceof Array*/, "Session.call: <args> must be an array []");
   util.assert(!kwargs || kwargs instanceof Object, "Session.call: <kwargs> must be an object {}");
   util.assert(!options || options instanceof Object, "Session.call: <options> must be an object {}");
Array.isArray() is implemented since JavaScript 1.8.5 and is now the recommended way to detect an object of type Array. instanceof Array is unreliable in some contexts.

Scott Reed

unread,
Aug 24, 2014, 1:36:46 PM8/24/14
to autob...@googlegroups.com
I forgot to respond to all your requests:
Yes, we just switched to nodeJS autobahn: autobahn.version is 0.9.4.

In the caller, just before calling Session.call, console.log(args instanceof Array) returns true. 
In the Session.call code, it returns false but Array.isArray(args) returns true.


Tobias Oberstein

unread,
Aug 24, 2014, 4:15:00 PM8/24/14
to autob...@googlegroups.com
> Array.isArray() is implemented since JavaScript 1.8.5 and is now the
> recommended way to detect an object of type Array. instanceof Array is
> unreliable in some contexts.

Thanks for tracking this down. We should probably fix that
systematically (this isn't the only place where instanceof is used):

https://github.com/tavendo/AutobahnJS/issues/102

What about "instanceof Object"?

What about "instance of Subscription" and the like?

Cheers,
/Tobias

Scott Reed

unread,
Aug 24, 2014, 7:36:31 PM8/24/14
to autob...@googlegroups.com
As I understand it, Javascript designers only screwed up the object model for Array. That's why they need to have Array.isArray() but not String.isString() or Object.isObject() or Subscription.isSubscription(). Everything else should be fine.

Tobias Oberstein

unread,
Aug 25, 2014, 1:51:09 AM8/25/14
to autob...@googlegroups.com
Am 25.08.2014 01:36, schrieb Scott Reed:
> As I understand it, Javascript designers /only /screwed up the object

"great". JS is the new C.

> model for Array. That's why they need to have Array.isArray() but /not
> /String.isString() or Object.isObject() or
> Subscription.isSubscription(). Everything else should be fine.

Alright, I did a point release 0.9.4-2 that should fix that.

Could you please check if that works for you?

Thanks!
/Tobias

Ryan Nestor

unread,
Aug 25, 2014, 11:10:45 AM8/25/14
to autob...@googlegroups.com
Thanks Scott/Tobias for tracking this down.  The RPC seems to be working now.

Ryan Nestor

unread,
Aug 27, 2014, 12:59:35 PM8/27/14
to autob...@googlegroups.com
The assert is failing on Objects in some cases as well.

I replaced the line:

util.assert(!kwargs || kwargs instanceof Object, "Session.call: <kwargs> must be an object {}");

with:

util.assert(!kwargs || typeof kwargs === "object", "Session.call: <kwargs> must be an object {}");

Which stopped the errors.  I understand this might not be a great solution.  

Tobias Oberstein

unread,
Aug 27, 2014, 4:34:17 PM8/27/14
to autob...@googlegroups.com
Am 27.08.2014 18:59, schrieb Ryan Nestor:
> The assert is failing on Objects in some cases as well.
>
> I replaced the line:
>
> util.assert(!kwargs || kwargs instanceof Object, "Session.call: <kwargs>
> must be an object {}");
>
> with:
>
> util.assert(!kwargs || typeof kwargs === "object", "Session.call:
> <kwargs> must be an object {}");
>
> Which stopped the errors. I understand this might not be a great solution.

Yeah. You can also remove the assert. That will stop the error as well;)

I will not change AutobahnJS again until someone can demonstrate a
solution that works on _all_ AutobahnJS targets. The stuff now works on
all targets I care.

JS is a piece of crap - I don't have time fiddling with a triviality
like this: "Is this duck an object or what?"

Oh mei: I wish Netscape would have done better. We could have Python in
the browser now instead of this duck shit.

Sorry for the rant,
/Tobias

>
> On Monday, August 25, 2014 10:10:45 AM UTC-5, Ryan Nestor wrote:
>
> Thanks Scott/Tobias for tracking this down. The RPC seems to be
> working now.
>
> On Monday, August 25, 2014 12:51:09 AM UTC-5, Tobias Oberstein wrote:
>
> Am 25.08.2014 01:36, schrieb Scott Reed:
> > As I understand it, Javascript designers /only /screwed up
> the object
>
> "great". JS is the new C.
>
> > model for Array. That's why they need to have Array.isArray()
> but /not
> > /String.isString() or Object.isObject() or
> > Subscription.isSubscription(). Everything else should be fine.
>
> Alright, I did a point release 0.9.4-2 that should fix that.
>
> Could you please check if that works for you?
>
> Thanks!
> /Tobias
>
> --
> You received this message because you are subscribed to the Google
> Groups "Autobahn" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to autobahnws+...@googlegroups.com
> <mailto:autobahnws+...@googlegroups.com>.
> To post to this group, send email to autob...@googlegroups.com
> <mailto:autob...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autobahnws/b04c8a60-feb8-4f00-bb12-1d8aa8737578%40googlegroups.com
> <https://groups.google.com/d/msgid/autobahnws/b04c8a60-feb8-4f00-bb12-1d8aa8737578%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages