msimerson / maxmind-geolite-mirror

Mirror MaxMind GeoIP dbs from geolite.maxmind.com
https://www.npmjs.com/package/maxmind-geolite-mirror
MIT License
10 stars 5 forks source link

Error messages during network problems #6

Closed megastef closed 8 years ago

megastef commented 8 years ago

Hi, I have seen this in docker containers having no internet connectivity. It looks potential errors are not handled correctly. To simulate the situation, I used an invalid hostname in config.js producing this output:

{ [Error: getaddrinfo ENOTFOUND geolite.maxmind.com1 geolite.maxmind.com1:80]
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'geolite.maxmind.com1',
  host: 'geolite.maxmind.com1',
  port: 80 }
fs.js:53
        throw backtrace;
        ^

Error: ENOENT: no such file or directory, unlink '/tmp/GeoIP.dat'
    at rethrow (fs.js:48:21)
    at makeCallback (fs.js:74:12)
    at Object.fs.unlink (fs.js:923:14)
    at ClientRequest.<anonymous> (/Users/stefan/sematext/logagent-js/node_modules/maxmind-geolite-mirror/bin/maxmind-geolite-mirror:88:12)
    at emitOne (events.js:77:13)
    at ClientRequest.emit (events.js:169:7)
    at Socket.socketErrorListener (_http_client.js:256:9)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at connectErrorNT (net.js:997:8)

Please add better error handling.

  1. Check if file exists before removal
  2. Add callback function to fs.unlink() to catch the error. bin/maxmind-geolite-mirror:88:12
msimerson commented 8 years ago
  1. Check if file exists before removal

This is an anti-pattern.

  1. Add callback function to fs.unlink()

Done in PR #7.

Thanks!