Nexuist / CoinMarketCapAPI

JSON API for coinmarketcap.com written in node and hosted on OpenShift.
https://coinmarketcap-nexuist.rhcloud.com
54 stars 24 forks source link

CoinFactory.js:25:64 - TypeError: Cannot read property '0' of null #22

Open altsheets opened 7 years ago

altsheets commented 7 years ago

any idea where this might be coming from?

0|main     | Wed Oct 18 2017 01:06:45 GMT+0000 (UTC): Server started.
0|main     | TypeError: Cannot read property '0' of null
0|main     |     at CoinFactory.produce (/root/CoinMarketCapAPI/lib/CoinFactory.js:25:64)
0|main     |     at Object.<anonymous> (/root/CoinMarketCapAPI/lib/CoinCrawler.js:30:33)
0|main     |     at initialize.exports.each (/root/CoinMarketCapAPI/node_modules/cheerio/lib/api/traversing.js:294:24)
0|main     |     at Request._callback (/root/CoinMarketCapAPI/lib/CoinCrawler.js:29:14)
0|main     |     at Request.self.callback (/root/CoinMarketCapAPI/node_modules/request/request.js:188:22)
0|main     |     at emitTwo (events.js:106:13)
0|main     |     at Request.emit (events.js:191:7)
0|main     |     at Request.<anonymous> (/root/CoinMarketCapAPI/node_modules/request/request.js:1171:10)
0|main     |     at emitOne (events.js:96:13)
0|main     |     at Request.emit (events.js:188:7)
PM2        | App [main] with id [0] and pid [3189], exited with code [1] via signal [SIGINT]
PM2        | Starting execution sequence in -fork mode- for app name:main id:0
PM2        | App name:main id:0 online
q0|main     | Wed Oct 18 2017 01:06:46 GMT+0000 (UTC): Server started.
0|main     | TypeError: Cannot read property '0' of null
0|main     |     at CoinFactory.produce (/root/CoinMarketCapAPI/lib/CoinFactory.js:25:64)
0|main     |     at Object.<anonymous> (/root/CoinMarketCapAPI/lib/CoinCrawler.js:30:33)
0|main     |     at initialize.exports.each (/root/CoinMarketCapAPI/node_modules/cheerio/lib/api/traversing.js:294:24)
0|main     |     at Request._callback (/root/CoinMarketCapAPI/lib/CoinCrawler.js:29:14)
0|main     |     at Request.self.callback (/root/CoinMarketCapAPI/node_modules/request/request.js:188:22)
0|main     |     at emitTwo (events.js:106:13)
0|main     |     at Request.emit (events.js:191:7)
0|main     |     at Request.<anonymous> (/root/CoinMarketCapAPI/node_modules/request/request.js:1171:10)
0|main     |     at emitOne (events.js:96:13)
0|main     |     at Request.emit (events.js:188:7)
PM2        | App [main] with id [0] and pid [3215], exited with code [1] via signal [SIGINT]
PM2        | Starting execution sequence in -fork mode- for app name:main id:0
PM2        | App name:main id:0 online
0|main     | Wed Oct 18 2017 01:06:47 GMT+0000 (UTC): Server started.
altsheets commented 7 years ago

As far as I can see, lines 25 CoinFactory.js:25:64:

      "symbol": tds.eq(4).text().match(/\s([a-z]|[0-9]|@)+\s/i)[0].trim().toLowerCase(),

and column 64 would point to a failing array index [0], so I guess

 tds.eq(4).text().match(/\s([a-z]|[0-9]|@)+\s/i)

is empty?

How come?

Has coinmarketcap changed its layout again?

Thanks for looking into this when you find the time.

altsheets commented 7 years ago

I have repaired that, see my fork:

altsheets ... /lib/CoinFactory.js#L30

the symbol actually (now?) also appears in the second column.

altsheets commented 7 years ago

Quite a bit of the CMC page layout must have been changed recently, so several things needed repair.

I have fixed what I could find, but I am not 1000% sure that everything is correct now.

Please another pair of eyes check my code for correct results, thanks:

https://github.com/altsheets/CoinMarketCapAPI/commits/master?author=altsheets

@Nexuist - pull request?