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

disallow rejecting non-errors #3

Closed
jonathanong opened this issue Feb 5, 2016 · 10 comments
Closed

disallow rejecting non-errors #3

jonathanong opened this issue Feb 5, 2016 · 10 comments

Comments

@jonathanong
Copy link

similar to throw 'string', rejecting anything but an error should be discouraged

@xjamundx
Copy link
Contributor

I like that idea. I haven't used promises too too much, but if that's a standard practice I think we should enforce it.

@xjamundx
Copy link
Contributor

xjamundx commented Mar 2, 2016

I like that

@ForbesLindesay
Copy link
Contributor

This is definitely standard practice. It would be a great rule to add.

@xjamundx
Copy link
Contributor

So http://eslint.org/docs/rules/no-throw-literal will handle the throw case already.

This rule would just be for Promise.reject(new Error('thing')) instead of Promise.reject('thing') is that right?

@ForbesLindesay
Copy link
Contributor

Also new Promise((resolve, reject) => reject('thing'))

@sindresorhus
Copy link

How should it handle custom errors? I suggest it accepts anything that matches /^(?:[A-Z][a-z0-9]*)*Error$/.

@ForbesLindesay
Copy link
Contributor

It should just follow the same rules as no-throw-literal. It's fine to do things like reject(getError()). All we're trying to do is guard against the common mistake of reject('Something went wrong')

@xjamundx
Copy link
Contributor

Yep I agree with this. I'll get it in there soon.

@macklinu
Copy link
Contributor

It looks like prefer-promise-reject-errors was added to the ESLint core in v3.14.0, so I'm wondering if this feature request is still relevant to eslint-plugin-promise. Anyone have thoughts on this?

@macklinu
Copy link
Contributor

macklinu commented Mar 8, 2018

I'm going to close this for now, since prefer-promise-reject-errors is available in ESLint core. Please comment if I'm missing something here and eslint-plugin-promise can provide functionality not present in the previously mentioned rule. Thanks!

@macklinu macklinu closed this as completed Mar 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants