Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot call method 'forEach' of undefined #53

Closed
shabbir92 opened this issue Dec 28, 2015 · 16 comments
Closed

TypeError: Cannot call method 'forEach' of undefined #53

shabbir92 opened this issue Dec 28, 2015 · 16 comments

Comments

@shabbir92
Copy link

[root@linx channels]# ./bin/channels
info - socket.io started

/opt/node-esl-master/examples/channels/node_modules/modesl/lib/esl/connection.js:594
doc.row.forEach(function(row) {
^
TypeError: Cannot call method 'forEach' of undefined
at /opt/node-esl-master/examples/channels/node_modules/modesl/lib/esl/connection.js:594:29
at Parser. (/opt/node-esl-master/examples/channels/node_modules/xml2js/lib/xml2js.js:255:20)
at Parser.emit (events.js:95:17)
at Object.saxParser.onclosetag (/opt/node-esl-master/examples/channels/node_modules/xml2js/lib/xml2js.js:225:24)
at emit (/opt/node-esl-master/examples/channels/node_modules/sax/lib/sax.js:615:33)
at emitNode (/opt/node-esl-master/examples/channels/node_modules/sax/lib/sax.js:620:3)
at closeTag (/opt/node-esl-master/examples/channels/node_modules/sax/lib/sax.js:861:5)
at Object.write (/opt/node-esl-master/examples/channels/node_modules/sax/lib/sax.js:1181:11)
at Parser.exports.Parser.Parser.parseString (/opt/node-esl-master/examples/channels/node_modules/xml2js/lib/xml2js.js:273:29)
at Parser.parseString (/opt/node-esl-master/examples/channels/node_modules/xml2js/lib/xml2js.js:6:61)

centos 7
[root@linx channels]# uname -a
Linux linx.lan 3.10.0-229.20.1.el7.x86_64 #1 SMP Tue Nov 3 19:10:07 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
kindly help me on this to resolve

@englercj
Copy link
Owner

Are you using the latest version? Line 594 isn't that line in the source.

@shabbir92
Copy link
Author

i have installed with this way
Downloaded as zip from https://github.com/englercj/node-esl/
after unzip goto examples/channels npm install
when i started above error displayed on terminal
when i tried to replace files in examples/channels/node_modules/modesl/lib/esl/
with new ones in node-esl-master/lib/esl then i see diffrent names like connection.js Connection.js
when i modify the index file with name esl.js then it says Error: Cannot find module 'node-uuid'
i think npm is installing old version of modesl

@englercj
Copy link
Owner

Go to your project's directory and do: npm install modesl.

Then in your project require('modesl').

That should give you the latest version from the package registry, using the proper install method. npm takes care of getting all the dependencies for you, and you can even check that the version is correct. It should be v1.1.6, which after installing you can see with npm ls --depth 0

@shabbir92
Copy link
Author

Thank you for help,
I am testing examples/channells and there https://github.com/englercj/node-esl/blob/master/examples/channels/package.json on line 12 "modesl": "0.x" this is why npm installing old version ,when i replaced this with "modesl": "1.x", now it is installed latest version,
npm ls --depth 0
channels@0.0.1 /opt/channels
├── express@3.21.2
├── eyes@0.1.8
├── modesl@1.1.6
├── socket.io@0.9.17
└── utile@0.3.0

and now error is

./bin/channels
info - socket.io started

events.js:72
throw er; // Unhandled 'error' event
^
TypeError: Cannot call method 'forEach' of undefined
at /opt/channels/node_modules/modesl/lib/esl/Connection.js:586:29
at Parser. (/opt/channels/node_modules/xml2js/lib/xml2js.js:483:18)
at Parser.emit (events.js:95:17)
at Object.onclosetag (/opt/channels/node_modules/xml2js/lib/xml2js.js:444:26)
at emit (/opt/channels/node_modules/sax/lib/sax.js:639:35)
at emitNode (/opt/channels/node_modules/sax/lib/sax.js:644:5)
at closeTag (/opt/channels/node_modules/sax/lib/sax.js:903:7)
at Object.write (/opt/channels/node_modules/sax/lib/sax.js:1293:13)
at Parser.exports.Parser.Parser.parseString (/opt/channels/node_modules/xml2js/lib/xml2js.js:502:31)
at Parser.parseString (/opt/channels/node_modules/xml2js/lib/xml2js.js:7:59)

@englercj
Copy link
Owner

Hmm, not sure. The only way this would happen (that I am aware of) is if the message from FSW was invalid. Can you let me see what the raw message looks like?

@shabbir92
Copy link
Author

Found problem on https://github.com/englercj/node-esl/blob/master/lib/esl/Connection.js#L578
parsed.rowCount = parseInt(doc.$.rowCount, 10);
and replaced with
parsed.rowCount = parseInt(doc.$.row_count, 10);
and ON
https://github.com/englercj/node-esl/blob/master/lib/esl/Connection.js#L585
} else {
replaced with
} else if (parsed.rowCount > 1){
And Now it working Thank You For help

@englercj
Copy link
Owner

englercj commented Jan 1, 2016

What version of FSW are you using? Did they change the XML format recently?

@shabbir92
Copy link
Author

"What version of FSW are you using?"
FreeSWITCH (Version 1.7.0 git 3b538d0 2015-12-16 08:07:19Z 64bit)

"Did they change the XML format recently?"
i have executed in fs_cli ' show channels as xml'
and result is below
< result row_count="0"/>
any other info you need ?

@englercj
Copy link
Owner

englercj commented Jan 2, 2016

can you do "npm ls --depth 0" and paste the output so I can see the version of dependencies you are using?

I think xml2js made a breaking change in a recent version. Try changing the version from "xml2js": "~0.4", to "xml2js": "0.4.6", in the package.json and reinstall the dependency. After confirming it is the proper version with npm ls --depth 0 try again and see if you get this error (using the original unmodified source, of course).

@shabbir92
Copy link
Author

i have tried as you asked ; with unmodified source
npm ls | grep xml2js
└─┬ xml2js@0.4.6
[root@linx channels]# npm ls --depth 0
channels@0.0.1 /opt/channels
├── express@3.21.2
├── eyes@0.1.8
├── modesl@1.1.6
├── socket.io@0.9.17
└── utile@0.3.0
[root@linx channels]# ./bin/channels
info - socket.io started

events.js:72
throw er; // Unhandled 'error' event
^
TypeError: Cannot call method 'forEach' of undefined
at /opt/channels/node_modules/modesl/lib/esl/Connection.js:586:29
at Parser. (/opt/channels/node_modules/modesl/node_modules/xml2js/lib/xml2js.js:428:18)
at Parser.emit (events.js:95:17)
at Object.onclosetag (/opt/channels/node_modules/modesl/node_modules/xml2js/lib/xml2js.js:397:26)
at emit (/opt/channels/node_modules/modesl/node_modules/sax/lib/sax.js:615:33)
at emitNode (/opt/channels/node_modules/modesl/node_modules/sax/lib/sax.js:620:3)
at closeTag (/opt/channels/node_modules/modesl/node_modules/sax/lib/sax.js:861:5)
at Object.write (/opt/channels/node_modules/modesl/node_modules/sax/lib/sax.js:1182:11)
at Parser.exports.Parser.Parser.parseString (/opt/channels/node_modules/modesl/node_modules/xml2js/lib/xml2js.js:447:31)
at Parser.parseString (/opt/channels/node_modules/modesl/node_modules/xml2js/lib/xml2js.js:6:59)

when i installed xml2js 0.4.6 or 0.4.15 error is same
i think error is because FSW is sending this < result row_count="0"/ > and
You are looking for rowCount instead of row_count and this is problem when parseInt function looks for expected string who is not there it returns NaN when i printed this variable via console.log
then printed value was NaN

@englercj
Copy link
Owner

englercj commented Jan 3, 2016

That is definitely the error, what I am trying to figure out is what has changed. That line of code has been working for years, so something is different in your configuration.

I'm trying determine if we need to change it to row_count in the source, but more importantly why it needs to be changed so that it can still work for all the people it has apparently been working for.

@shabbir92
Copy link
Author

Today i have aded ' console.log("doc:",doc)' before https://github.com/englercj/node-esl/blob/master/lib/esl/Connection.js#L578 To Look raw message
doc: { '$': { row_count: '0' } }
debug - websocket writing 5:::{"name":"data","args":[{"uuid":null,"data":{"rows":{}}}]}
doc: { '$': { row_count: '1' },
row:
{ '$': { row_id: '1' },
uuid: '6ba91232-b2b2-11e5-9760-6d9fe5d3764d',
direction: 'inbound',
created: '2016-01-04 12:11:48',
created_epoch: '1451891508',
name: 'skypopen/skype103',
state: 'CS_EXECUTE',
cid_name: '',
cid_num: '',
ip_addr: '',
dest: 'skype_in',
application: 'sleep',
application_data: '2000',
dialplan: 'XML',
context: 'default',
read_codec: 'L16',
read_rate: '16000',
read_bit_rate: '256000',
write_codec: 'L16',
write_rate: '16000',
write_bit_rate: '256000',
secure: '',
hostname: 'linx.lan',
presence_id: '',
presence_data: '',
callstate: 'ACTIVE',
callee_name: '',
callee_num: '',
callee_direction: '',
call_uuid: '',
sent_callee_name: '',
sent_callee_num: '',
initial_cid_name: '',
initial_cid_num: '',
initial_ip_addr: '',
initial_dest: 'skype_in',
initial_dialplan: 'XML',
initial_context: 'default' } }
debug - websocket writing 5:::{"name":"data","args":[{"uuid":null,"data":{"rows":{"6ba91232-b2b2-11e5-9760-6d9fe5d3764d":{"uuid":"6ba91232-b2b2-11e5-9760-6d9fe5d3764d","direction":"inbound","created":"2016-01-04 12:11:48","created_epoch":"1451891508","name":"skypopen/skype103","state":"CS_EXECUTE","cid_name":"","cid_num":"","ip_addr":"","dest":"skype_in","application":"sleep","application_data":"2000","dialplan":"XML","context":"default","read_codec":"L16","read_rate":"16000","read_bit_rate":"256000","write_codec":"L16","write_rate":"16000","write_bit_rate":"256000","secure":"","hostname":"linx.lan","presence_id":"","presence_data":"","callstate":"ACTIVE","callee_name":"","callee_num":"","callee_direction":"","call_uuid":"","sent_callee_name":"","sent_callee_num":"","initial_cid_name":"","initial_cid_num":"","initial_ip_addr":"","initial_dest":"skype_in","initial_dialplan":"XML","initial_context":"default"}}}}]}

And tried to look into Sources At https://freeswitch.org/stash/projects/FS/repos/freeswitch/browse/src/mod/applications/mod_commands/mod_commands.c
Unfortunatly Not found Anywhere in v1.2 or v1.4 or v1.6 or v1.7 rowCount Only Found row_count
And i am wonder how this was Working before ?

@shabbir92
Copy link
Author

To figure Out why this is Happend
I have tried To look into sources And Downloaded modesl v0.0.11 at line 586 Found
parsed.row_count = parseInt(doc['$'].row_count, 10);
But in v 1.1.1 https://github.com/englercj/node-esl/blob/v1.1.1/lib/esl/Connection.js#L581
it is changed to
parsed.rowCount = parseInt(doc.$.rowCount, 10);
and this is problem (what i understand)

@englercj
Copy link
Owner

englercj commented Jan 4, 2016

I'm dumb, I should've just looked at the blame in the first place. So sorry about all the trouble, a new version is published that should fix your issue.

@shabbir92
Copy link
Author

Dear brother hello,
You have forgot to replace https://github.com/englercj/node-esl/blob/master/lib/esl/Connection.js#L585
with
} else if (parsed.rowCount > 1){
Due to this problem not solved because sometimes row count is '0'
[root@linx channels]# npm ls --depth 0
channels@0.0.1 /opt/channels
├── express@3.21.2
├── eyes@0.1.8
├── modesl@1.1.7
├── socket.io@0.9.17
└── utile@0.3.0

[root@linx channels]# ./bin/channels
info - socket.io started

events.js:72
throw er; // Unhandled 'error' event
^
TypeError: Cannot call method 'forEach' of undefined
at /opt/channels/node_modules/modesl/lib/esl/Connection.js:586:29
at Parser. (/opt/channels/node_modules/xml2js/lib/xml2js.js:483:18)
at Parser.emit (events.js:95:17)
at Object.onclosetag (/opt/channels/node_modules/xml2js/lib/xml2js.js:444:26)
at emit (/opt/channels/node_modules/sax/lib/sax.js:639:35)
at emitNode (/opt/channels/node_modules/sax/lib/sax.js:644:5)
at closeTag (/opt/channels/node_modules/sax/lib/sax.js:903:7)
at Object.write (/opt/channels/node_modules/sax/lib/sax.js:1293:13)
at Parser.exports.Parser.Parser.parseString (/opt/channels/node_modules/xml2js/lib/xml2js.js:502:31)
at Parser.parseString (/opt/channels/node_modules/xml2js/lib/xml2js.js:7:59)

kindly update it again and please if u Don't mind also update
https://github.com/englercj/node-esl/blob/master/examples/channels/package.json#L12
Thank You

@englercj
Copy link
Owner

englercj commented Jan 5, 2016

You're right, fixed now hopefully!

davehorton pushed a commit to davehorton/node-esl that referenced this issue Sep 14, 2018
davehorton pushed a commit to davehorton/node-esl that referenced this issue Sep 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants