Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boom doesn't consider message not set directly on error object when deciding whether it is a compatible error #246

Closed
chrift opened this issue Sep 24, 2019 · 3 comments
Assignees
Labels
bug
Milestone

Comments

@chrift
Copy link

@chrift chrift commented Sep 24, 2019

As a result of the fixes for #216, any error messages set on err.output.payload.error throw the following error:

TypeError: Cannot read property 'configurable' of undefined
    at Object.internals.initialize (.../node_modules/@hapi/boom/lib/index.js:394:27)

It looks like even though on line 385 it checks for an error message stored in err.output.payload.error, it doesn't consider them on line 394.

One possible solution to this could be:

// node_modules/@hapi/boom/lib/index.js:385

    const messageLocation = {
        err,
        message: 'message'
    }

    if (!message &&
        !err.message) {

        err.reformat();
        message = err.output.payload.error;

        messageLocation.err = err.output.payload
        messageLocation.message = 'error'
    }

    if (message) {
        const props = Object.getOwnPropertyDescriptor(messageLocation.err, messageLocation.message) || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(messageLocation.err), messageLocation.message);
        Hoek.assert(props.configurable && !props.get, 'The error is not compatible with boom');

        err.message = message + (err.message ? ': ' + err.message : '');
        err.output.payload.message = err.message;
    }

I can open a PR with this change if desired.

@chrift

This comment has been minimized.

Copy link
Author

@chrift chrift commented Sep 24, 2019

I have opened pr #247 containing style appropriate code from above

@hueniverse hueniverse self-assigned this Sep 24, 2019
@hueniverse

This comment has been minimized.

Copy link
Member

@hueniverse hueniverse commented Sep 24, 2019

Can you provide a test case? Just a quick example of how to reproduce this?

@chrift

This comment has been minimized.

Copy link
Author

@chrift chrift commented Sep 25, 2019

Hey Eran,

Here is an example of what led me to find this error:

const Boom = require('./')

class Example extends Error {
  constructor (message) {
    super(message)
    Boom.boomify(this)
  }
}

// console.log(Error())
console.log(new Example())
@hueniverse hueniverse added the bug label Sep 27, 2019
@hueniverse hueniverse added this to the 8.0.0 milestone Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.