ddsol / speedtest.net

node.js SpeedTest.net client module
MIT License
611 stars 124 forks source link

Cannot read property 'servers' of undefined #44

Closed JohnPekl closed 5 years ago

JohnPekl commented 7 years ago

events.js:160 throw er; // Unhandled 'error' event ^

TypeError: Cannot read property 'servers' of undefined at gotServers (/home/abc/Desktop/test/speedNodejs/node_modules/speedtest-net/index.js:550:29) at /home/abc/Desktop/test/speedNodejs/node_modules/speedtest-net/index.js:48:16 at /home/abc/Desktop/test/speedNodejs/node_modules/speedtest-net/index.js:241:7 at Parser. (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/xml2js.js:489:18) at emitOne (events.js:96:13) at Parser.emit (events.js:188:7) at Object.onclosetag (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/xml2js.js:447:26) at emit (/home/abc/Desktop/test/speedNodejs/node_modules/sax/lib/sax.js:640:35) at emitNode (/home/abc/Desktop/test/speedNodejs/node_modules/sax/lib/sax.js:645:5) at closeTag (/home/abc/Desktop/test/speedNodejs/node_modules/sax/lib/sax.js:905:7) at Object.write (/home/abc/Desktop/test/speedNodejs/node_modules/sax/lib/sax.js:1452:13) at Parser.exports.Parser.Parser.parseString (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/xml2js.js:508:31) at Parser.parseString (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/xml2js.js:7:59) at exports.parseString (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/xml2js.js:540:19) at /home/abc/Desktop/test/speedNodejs/node_modules/speedtest-net/index.js:239:5 at /home/abc/Desktop/test/speedNodejs/node_modules/speedtest-net/index.js:48:16

ddsol commented 7 years ago

I can't reproduce this. It works fine for me. What version are you using? Could you add a console.log(require('util').inspect(servers, { depth: null })); before line 550?

JohnPekl commented 7 years ago

Thanks for your module,

I am using version "speedtest-net": "^1.2.12", This issues infrequently occurs as it leaves my implemented code run for a whole day with the following (the error only occurred two times):

`setInterval(function pingTest() {

      test = speedTest({
          maxTime: 5000
      });
      return pingTest;
  }(), 300000);`

I will add the log statement and will comment here if it occurs again.

JohnPekl commented 7 years ago

I tried with the new version of your module "speedtest-net": "^1.3.1" and it occurred the same issues. Here is the log following your instruction.

547 function gotServers(err, servers) {

548 if (err || !servers) return nextServer(err);

549 console.log(require('util').inspect(servers, { depth: null }));

550 var s = servers.settings.servers[0].server;

{ html: { '$': { xmlns: 'http://www.w3.org/1999/xhtml', 'xml:lang': 'en', lang: 'en' }, head: [ { title: [ '404 - Not Found' ] } ], body: [ { h1: [ '404 - Not Found' ] } ] } } events.js:160 throw er; // Unhandled 'error' event ^

TypeError: Cannot read property 'servers' of undefined at gotServers (/home/abc/Desktop/test/cdnnodejs/node_modules/speedtest-net/index.js:550:29) at /home/abc/Desktop/test/speedNodejs/node_modules/speedtest-net/index.js:47:16 at /home/abc/Desktop/test/speedNodejs/node_modules/speedtest-net/index.js:240:7 at Parser. (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/parser.js:303:18) at emitOne (events.js:96:13) at Parser.emit (events.js:188:7) at Object.onclosetag (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/parser.js:261:26) at emit (/home/abc/Desktop/test/speedNodejs/node_modules/sax/lib/sax.js:624:35) at emitNode (/home/abc/Desktop/test/speedNodejs/node_modules/sax/lib/sax.js:629:5) at closeTag (/home/abc/Desktop/test/speedNodejs/node_modules/sax/lib/sax.js:889:7) at Object.write (/home/abc/Desktop/test/speedNodejs/node_modules/sax/lib/sax.js:1436:13) at Parser.exports.Parser.Parser.parseString (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/parser.js:322:31) at Parser.parseString (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/parser.js:5:59) at exports.parseString (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/parser.js:354:19) at /home/abc/Desktop/test/speedNodejs/node_modules/speedtest-net/index.js:238:5 at /home/abc/Desktop/test/speedNodejs/node_modules/speedtest-net/index.js:47:16

ddsol commented 5 years ago

Closing this for inactivity. Also, looks like SpeedTest couldn't find their page so I'm not sure how to fix that... I could make the error better but it would still not work.