ESLint InterlaceESLint Interlace
Plugin: reliabilityRules

no-unhandled-promise

ESLint rule documentation for no-unhandled-promise

๐Ÿ“ก Live from GitHub โ€” This documentation is fetched directly from no-unhandled-promise.md and cached for 6 hours.

Keywords: unhandled promise, promise rejection, async error handling, Promise, async/await, error handling, Node.js, JavaScript promises, async patterns, promise chains, try/catch, await, error propagation, CWE-1024, SonarQube RSPEC-4635

Disallow unhandled Promise rejections with LLM-optimized suggestions for proper async error handling. This rule detects promises that are created but never have

Disallow unhandled Promise rejections with LLM-optimized suggestions for proper async error handling. This rule detects promises that are created but never have their rejection handled, preventing silent failures in production applications.

Quick Summary

AspectDetails
SeverityError (production safety)
Auto-FixโŒ No (complex logic)
CategoryError Handling
ESLint MCPโœ… Optimized for ESLint MCP integration
Best ForProduction applications, async codebases
Suggestionsโœ… Add .catch(), use try/catch, use await

Rule Details

Why This Matters

IssueImpactSolution
๐Ÿ”’ Silent FailuresErrors swallowed without loggingProper error handling
๐Ÿ› DebuggingHard to trace async failuresCentralized error handling
โšก ReliabilityApplication crashes unexpectedlyGraceful error recovery
๐Ÿ“Š MonitoringNo visibility into promise failuresError tracking & alerting

Configuration

OptionTypeDefaultDescription
ignoreInTestsbooleantrueSkip promise checks in test files
ignoreVoidExpressionsbooleanfalseSkip promises in void expressions

Examples

โŒ Incorrect

// Unhandled promise rejection
fetchUserData(userId);

// Promise chain without error handling
apiCall()
  .then(processData)
  .then(saveToDatabase);

// Async function without await or error handling
async function processOrder(orderId) {
  validateOrder(orderId); // Promise not handled
  return orderId;
}

โœ… Correct

// Handle with .catch()
fetchUserData(userId)
  .catch(error => {
    logger.error('Failed to fetch user data', { userId, error });
  });

// Complete promise chain
apiCall()
  .then(processData)
  .then(saveToDatabase)
  .catch(error => {
    logger.error('API pipeline failed', { error });
  });

// Use try/catch in async functions
async function processOrder(orderId) {
  try {
    await validateOrder(orderId);
    return orderId;
  } catch (error) {
    logger.error('Order validation failed', { orderId, error });
    throw error;
  }
}

// Or use await at the call site
async function handleOrder(orderId) {
  await processOrder(orderId); // Error will propagate
}

Configuration Examples

Basic Usage

// eslint.config.mjs
export default [
  {
    rules: {
      'reliability/no-unhandled-promise': 'error',
    },
  },
];

Ignore Test Files

{
  rules: {
    'reliability/no-unhandled-promise': ['error', {
      ignoreInTests: true  // Default: true
    }]
  }
}

Strict Mode (No Exceptions)

{
  rules: {
    'reliability/no-unhandled-promise': ['error', {
      ignoreInTests: false,
      ignoreVoidExpressions: false
    }]
  }
}

LLM-Optimized Output

๐Ÿšจ [CWE-1024](https://cwe.mitre.org/data/definitions/1024.html) | Unhandled promise rejection detected | HIGH
   Fix: Add .catch() handler or use try/catch | https://rules.sonarsource.com/javascript/RSPEC-4635/

Suggestions:
  ๐Ÿ”ง Add .catch(error => { ... })
  ๐Ÿ”„ Use try/catch block
  โšก Use await in async function

Advanced Usage

Integration with Error Boundaries

// React component with error boundary
class ErrorBoundary extends React.Component {
  componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
    // Handle async errors from promises
    logger.error('React error boundary caught error', {
      error: error.message,
      componentStack: errorInfo.componentStack
    });
  }
}

// Usage
<ErrorBoundary>
  <AsyncComponent />
</ErrorBoundary>

Global Unhandled Rejection Handler

// Global handler for truly unhandled rejections
process.on('unhandledRejection', (reason, promise) => {
  logger.error('Unhandled promise rejection', {
    reason,
    promise: promise.toString()
  });
  // Don't exit process in production
});

When Not To Use

ScenarioRecommendation
๐Ÿงช PrototypingDisable or use warning level
๐Ÿ“š TutorialsAdd to ignorePatterns
๐Ÿ”ง Build ScriptsUse ignorePatterns: ['scripts']

Comparison with Alternatives

Featureno-unhandled-promiseeslint-plugin-promiseESLint built-in
Promise Detectionโœ… Static analysisโœ… Runtime checksโŒ No
Auto-FixโŒ NoโŒ NoโŒ No
LLM-Optimizedโœ… YesโŒ NoโŒ No
Customizableโœ… Yesโš ๏ธ LimitedโŒ No

Error Message Format

๐Ÿšจ [CWE-1024](https://cwe.mitre.org/data/definitions/1024.html) | Unhandled promise rejection detected | HIGH
   Fix: Add .catch() handler or use try/catch | https://rules.sonarsource.com/javascript/RSPEC-4635/

Further Reading

Known False Negatives

The following patterns are not detected due to static analysis limitations:

Dynamic Variable References

Why: Static analysis cannot trace values stored in variables or passed through function parameters.

// โŒ NOT DETECTED - Value from variable
const value = externalSource();
processValue(value); // Variable origin not tracked

Mitigation: Implement runtime validation and review code manually. Consider using TypeScript branded types for validated inputs.

Wrapped or Aliased Functions

Why: Custom wrapper functions or aliased methods are not recognized by the rule.

// โŒ NOT DETECTED - Custom wrapper
function myWrapper(data) {
  return internalApi(data); // Wrapper not analyzed
}
myWrapper(unsafeInput);

Mitigation: Apply this rule's principles to wrapper function implementations. Avoid aliasing security-sensitive functions.

Imported Values

Why: When values come from imports, the rule cannot analyze their origin or construction.

// โŒ NOT DETECTED - Value from import
import { getValue } from './helpers';
processValue(getValue()); // Cross-file not tracked

Mitigation: Ensure imported values follow the same constraints. Use TypeScript for type safety.

On this page

No Headings