taskrabbit/elasticsearch-dump — pull request #55 by brianreavis (2014-12-05 20:24:00+00:00)
Title: Improved JSON parse error log messages

This pull request improves the verbosity of log messages when a JSON parse error happens. If a user (like me) mistypes a basic auth password, elasticdump gives a cryptic error message that doesn't make the problem immediately obvious.

### Before

```
Fri, 05 Dec 2014 20:05:04 GMT | starting dump
Fri, 05 Dec 2014 20:05:04 GMT | got 1 objects from source elasticsearch (offset: 0)
Fri, 05 Dec 2014 20:05:04 GMT | {}
Fri, 05 Dec 2014 20:05:04 GMT | dump ended with error
```
```
Fri, 05 Dec 2014 20:06:59 GMT | starting dump
Fri, 05 Dec 2014 20:06:59 GMT | got 1 objects from source elasticsearch (offset: 0)

SyntaxError: Unexpected token <
at Object.parse (native)
at Object.module.exports.parse (/Users/brianreavis/Repositories/elasticsearch-dump/lib/json.js:2:14)
at elasticsearch.setMapping (/Users/brianreavis/Repositories/elasticsearch-dump/lib/transports/elasticsearch.js:142:18)
at elasticsearch.set (/Users/brianreavis/Repositories/elasticsearch-dump/lib/transports/elasticsearch.js:131:14)
at /Users/brianreavis/Repositories/elasticsearch-dump/elasticdump.js:80:17
at Request._callback (/Users/brianreavis/Repositories/elasticsearch-dump/lib/transports/elasticsearch.js:38:13)
at Request.self.callback (/Users/brianreavis/Repositories/elasticsearch-dump/node_modules/request/request.js:373:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request. (/Users/brianreavis/Repositories/elasticsearch-dump/node_modules/request/request.js:1318:14)
at Request.EventEmitter.emit (events.js:117:20)
```

### After

```
Fri, 05 Dec 2014 20:22:03 GMT | starting dump
Fri, 05 Dec 2014 20:22:03 GMT | got 1 objects from source elasticsearch (offset: 0)
Fri, 05 Dec 2014 20:22:03 GMT | failed to parse json (message: "Unexpected token <") - source: "\r\n

401 Authorization Required

\r\n

\r\n

401 Authorization Required

\r\n

nginx/1.6.2\r\n

\r\n\r\n"
Fri, 05 Dec 2014 20:22:03 GMT | dump ended with error
```