Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upWhy prefer-promise-reject-errors?? #1273
Comments
This comment has been minimized.
This comment has been minimized.
|
This is an edge case, almost all of the time you want an error with the rejection, anything else e.g. a string, is most likely bad practice as it loses the stack trace and makes it a nightmare to track down where the error came from. Rejecting or throwing a string or an object without a stack trace is frustratingly common. Since the rule promotes a good practice for the majority of cases it should probably remain enabled for Additionally you could consider returning Alternatively you could reject a custom |
Jakobud commentedApr 14, 2019
What version of standard? Latest
What operating system, Node.js, and npm version? Ubuntu 16, Node.js 9.11.1, npm 6.4.1
Why is Standard using
prefer-promise-reject-errors? If you are assuming that every Promise rejection is the result of an error that should be anew Error()then you are assuming too much. A perfect example that led me here: I'm developing some extensions for VSCode and many of the UI interactions that are initiated from the extension return a Promise. For example, asking the user to pick a file for some action to happen on that file. If the user changes their mind and does not pick a file, then the only way to handle this is is a Promisereject()in order to keep the "action" from happening. But returning an actual Error doesn't make sense here. The extension is behaving perfectly normal. No error has occurred. But if you are using StandardJS it's forcing me to unnecessarily throw an Error object.Doesn't really make sense to enforce such a thing for all situations.