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

#1

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: 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

0 Likes

#2

I forgot to mention that the corrupted string is one of three in the array being passed and only one of them is affected.

···

On Friday, August 22, 2014 4:33:55 PM UTC-4, Scott Reed wrote:

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: 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

0 Likes

#3

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

···

2014-08-22 22:59 GMT+02:00 Scott Reed sr...@avacoda.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.

On Friday, August 22, 2014 4:33:55 PM UTC-4, Scott Reed wrote:

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: 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

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.

0 Likes

#4

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: must be a string”);

util.assert(!args || args instanceof Array, “Session.call: must be an array []”);

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

util.assert(!options || options instanceof Object, “Session.call: must be an object {}”);

If I comment out the highlighted line it works fine.

0 Likes

#5

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.

···

Am 24.08.2014 00:39, schrieb Scott Reed:

--
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>.
For more options, visit https://groups.google.com/d/optout.

0 Likes

#6

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: must be a string”);

util.assert(!args || Array.isArray(args) /args instanceof Array/, “Session.call: must be an array []”);

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

util.assert(!options || options instanceof Object, “Session.call: 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.

0 Likes

#7

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.

0 Likes

#8

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

0 Likes

#9

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.

0 Likes

#10

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

···

Am 25.08.2014 01:36, schrieb Scott Reed:

0 Likes

#11

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

0 Likes

#12

The assert is failing on Objects in some cases as well.

I replaced the line:

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

with:

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

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

···

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

0 Likes

#13

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

···

Am 27.08.2014 18:59, schrieb Ryan Nestor:

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>.
For more options, visit https://groups.google.com/d/optout.

0 Likes