express icon indicating copy to clipboard operation
express copied to clipboard

feat: add deprecation warnings for invalid sendStatus parameters to prepare for Express v6

Open Vedant224 opened this issue 4 months ago • 1 comments

Summary

Implements deprecation warnings for invalid status codes passed to res.sendStatus(), as recommended by maintainers. This provides a smooth migration path from the current throwing behavior to stricter validation planned for Express 6.

Background

Previously, res.sendStatus() threw a TypeError for non-number inputs. This PR introduces deprecation warnings for such inputs in Express 5, maintaining backward compatibility while preparing for Express 6, where these inputs will throw errors.

Changes Made

  • Deprecation Warning: Emits warnings for non-number status codes using Express's depd module
  • Graceful Fallback: Invalid inputs now return status 500 instead of throwing
  • Express 6 Migration Path: Warning messages clearly state that errors will be thrown in Express 6
  • Comprehensive Tests: Added test cases for undefined, BigInt, and string inputs
  • Safe Serialization: Uses String() to safely convert invalid values in warnings

Backward Compatibility

  • No breaking changes; existing valid code continues to work seamlessly
  • Invalid inputs warn instead of causing immediate crashes
  • Provides clear, actionable warnings to help developers fix issues before migrating to Express 6

Test Results

All 1,242 tests pass, including the new comprehensive sendStatus test coverage validating fallback behavior and deprecation logic.

Implementation Details

  • Uses Express's standard depd deprecation system consistent with other Express warnings
  • Follows established Express patterns and error messaging
  • Provides clear, actionable warning messages for maintainers and users

Vedant224 avatar Sep 18 '25 12:09 Vedant224