prefer-promise-reject-errors
It’s good practice to only reject Promises withError objects. Errors automatically store stack traces for debugging.
Rule Type: Suggestion
Fixable: No
Fixable: No
Why This Rule Exists
Error objects provide:
- Stack traces: See where rejection occurred
- Standard format: Consistent error handling
- Type checking: Can check if value is Error
- Better debugging: Shows full call stack
Rule Details
This rule enforces that Promises are only rejected withError objects.
Examples
Incorrect Code
Correct Code
Options
allowEmptyReject
Type: booleanDefault:
false
Allow Promise.reject() with no arguments.
Benefits of Error Objects
Stack Traces
Type Checking
Error Logging Services
Common Patterns
API Errors
Validation Errors
Timeout Errors
Custom Error Types
Extending Error
Known Limitations
This rule uses static analysis and cannot guarantee that you only reject with Errors:Async Functions
This rule doesn’t checkthrow in async functions (they become rejections), but no-throw-literal does: