Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

'message' attribute is not passed to errs.create() when proxing errors from couchdb (or any other error) #96

Closed
osher opened this Issue Jul 24, 2012 · 7 comments

Comments

Projects
None yet
2 participants

osher commented Jul 24, 2012

Ok, so there's not a single place to fix all the errors that are passed by nano, but there's a sigle palce to fix all the errors proxied from couch, and there is a signle way to fix all of them:

All you have to do is pass a 'message' property to the creator or merger of the errors.

The result will be errors that make sense in all the inspectors (utils.inspect, eyes.inspect, etc), in all the logs, and in most unit-test frameworks , that usually float up the message (which currently is unfortunately for all the errors "Unspecified error").

{
    message: 'Unspecified error',
    stacktrace: [
        'Error: Unspecified error',
        '    at Request._callback (D:\\....
        '    at Request.callback (D:\\...
        '    at Request.<anonymous> (native)',
        '    at Request.<anonymous> (events.js:70:17)',
        '    at Request.emit (D:\\...
        '    at Request.<anonymous> (D:\\...
        '    at Request.<anonymous> (events.js:67:17)',
        '    at Request.emit (D:\\...
        '    at IncomingMessage.<anonymous> (D:\\...
    ],
    request: {
        headers: { content-type: 'application/json', accept: 'a
        callback: Function,
        uri: 'http://localhost:5984/ua/test',
        jar: false,
        method: 'GET'
    },
    scope: 'couch',
    name: 'Error',
    status-code: 404,
    description: 'Unspecified error',
    status_code: 404,
    error: 'not_found',
    errid: 'non_200',
    arguments: undefined,
    headers: {
        cache-control: 'must-revalidate',
        content-type: 'application/json',
        status-code: 404,
        uri: 'http://localhost:5984/ua/test',
        date: 'Mon, 23 Jul 2012 20:07:22 GMT'
    },
    stack: 'Error: Unspecified error\n    at Request._callback

osher commented Jul 24, 2012

on lines 287 - 299

        else { // proxy the error directly from couchdb
          log({err: 'couch', body: parsed, headers: rh});
          if (!parsed) { parsed = {}; }
          errs.handle(errs.merge(errs.create(parsed),
             { "scope"       : "couch"
             , "status_code" : status_code
             , "status-code" : status_code
             , "request"     : req
             , "headers"     : rh
             , "errid"       : "non_200"
             }), callback);
          return stream;
        }

if i get you right - parsed - would usually be the JSON experession spat by couch-db.
in this case, decorate it with:

parsed.message = parsed.reason

just before passing it to errs.create(parsed).

I'm not aware on what cases you expect no body or no parsed - probably some fiddle with list functions I suppose, in that case - it would be fair to pass 'unspecified error' if the list function returned no ouput comperhandable by JSON parser.

@dscape dscape closed this Jul 24, 2012

Owner

dscape commented Jul 24, 2012

This is not getting fixed unless you submit a PR :)

It seems like you know how to do it, go for it. Add tests !

osher commented Jul 25, 2012

What's a PR? Public relations?

osher commented Jul 25, 2012

Ah.. pull request.

You state in your README.md to open an issue before start working on it.
I was following orders - and then you closed it.

Should I open a new issue ?

Owner

dscape commented Jul 25, 2012

I'll email you to help.

Expect this soon

osher commented Jul 25, 2012

I mailed you from a mail I check much often, lets communicate there...

On Wed, Jul 25, 2012 at 4:13 PM, Nuno Job <
reply@reply.github.com

wrote:

I'll email you to help.

Expect this soon


Reply to this email directly or view it on GitHub:
#96 (comment)

Owner

dscape commented Jul 25, 2012

Just replied with a "how to do a PR" blogpost

@dscape dscape added a commit that referenced this issue Jul 30, 2012

@dscape dscape [errs fix] fixes #96 and #93 17795dd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment