ekalinin / robots.js

Parser for robots.txt for node.js
MIT License
66 stars 21 forks source link

praser.parse() throwing Cannot read property \'length\' of undefined' #29

Closed zackiles closed 6 years ago

zackiles commented 6 years ago

My code

    import robots from 'robots';
    const robotsParser = new robots.RobotsParser();
    const url = 'https://google.com/robots.txt';

    return new Promise((resolve, reject) => {
      robotsParser.setUrl(url, (parser, success) => {
        if (success) {
          resolve(parser.parse());
        } else {
          reject();
        }
      });
    });

This returns

'TypeError: Cannot read property \'length\' of undefined',
     '    at RobotsParser.parse (/home/debian/project/node_modules/robots/lib/parser.js:250:28)',
     '    at robotsParser.setUrl (/home/debian/project/src/lib/site-mapper.js:24:32)',
     '    at IncomingMessage.<anonymous> (/home/debian/project/node_modules/robots/lib/parser.js:191:9)',
     '    at emitNone (events.js:91:20)',
     '    at IncomingMessage.emit (events.js:188:7)',
     '    at endReadableNT (_stream_readable.js:975:12)',
     '    at _combinedTickCallback (internal/process/next_tick.js:80:11)',
     '    at process._tickCallback (internal/process/next_tick.js:104:9)'

Using: node v7.8.0 npm 5.0.0 robots 0.10.1

zackiles commented 6 years ago

Hmm, I believe this is just not the intended use, I was assuming it would return the text version of the robots.