nelsonic / github-scraper

πŸ•· πŸ•Έ crawl GitHub web pages for insights we can't GET from the API ... πŸ’‘

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: Cannot read property 'match' of undefined on switcher.js:34

nelsonic opened this issue Β· comments

Oh undefined my old nemesis how I've NOT missed you!
image

/dwyl/top/node_modules/github-scraper/lib/switcher.js:34
  if(url.match(/\.atom/)) { // feed parser has its own request handler
        ^

TypeError: Cannot read property 'match' of undefined
    at switcher (/dwyl/top/node_modules/github-scraper/lib/switcher.js:34:9)
    at Timeout.<anonymous> (/dwyl/top/3_find_sheeple_who_follow.js:25:7)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)

I'm so tempted to re-write this in Elixir or Haskell ... if only I could justify the time!!

Annoyingly there are a few users who have the word undefined in their GitHub username
e.g: https://github.com/undefined and https://github.com/undefined-zola ...

so the check in url_validator.js#L13-L15:

if(!url || url.length === 0 || typeof url === 'undefined' || url.match(/undefined/)){
return callback(400);
}

is always going to 400 ... 😞

Ok I've found quite a few Jokers who think they are hilarious and have the word undefined in their GitHub Username. I have two choices:

  1. continue to throw an error when undefined is in the url ❗️
  2. write a few tests for this condition and address the issue ... πŸ™„

this genius was super creative with his Username: https://github.com/nullnullundefined
image

πŸ™„

Of the 284k GitHub users "Hansel" is monitoring 21 have the word undefined in their username:
image

Why do people need to be difficult!!

the current test:

test('url_validator rejects a url containing word "undefined"', function(t) {
validate('/undefined/followers', function(err){
console.log(err)
t.ok(err, 400, 'Receive 400 Error when URL resembles "undefined" ');
t.end();
});
})

Does not have any context ...
So I'm going to update it!
The benefits of being the "only user" of this module is that I can make changes. πŸ˜‰

the undefined user is a legit person:
image