Uh oh!
There was an error while loading. Please reload this page.
fix: display the correct message when passing a bigint to res.status. - #6758
fix: display the correct message when passing a bigint to res.status.#6758Vedant224 wants to merge 4 commits into
bigint to res.status.#6758Conversation
…on error (expressjs#6756) - Add type checking in sendStatus() method to throw TypeError for non-number inputs - Prevents uncaught 'Do not know how to serialize a BigInt' error - Add test coverage for BigInt status code input - Maintains backward compatibility with existing error patterns Fixesexpressjs#6756
Uh oh!
There was an error while loading. Please reload this page.
bjohansebas
left a comment
There was a problem hiding this comment.
This looks good, although this will be released for version 6 since it would be a breaking change, and we should first release a warning in version 5. Could you create a new PR to add a deprecation message?
@bjohansebas I've created the deprecation warning PR as requested. I kept it targeting master since that shows my actual 2-file changes cleanly. When I tried changing the target to 5.x it showed 36 changes (difference between branches). Should I leave it targeting master and you'll handle getting it into Express v5, or would you prefer a different approach for the branch targeting? The deprecation warning PR is ready for review - it adds the deprecate() call for non-number values in sendStatus(). |
krzysdz
commented
Oct 29, 2025
I don't think that it would be a breaking change - 5.x already includes validation that was added in #4212. This probably could be documented better, because it's mentioned only for The problem with serialization occurs during creation of the validation error message (see #6756 (comment)). |
jonchurch
left a comment
There was a problem hiding this comment.
We centralize our validation for status codes in the .status method which sendStatus relies on.
Any changes to the validation should happen there.
jonchurch
commented
Dec 12, 2025
Also it's not an uncaught exception, we expect a throw for invalid status and it will be handled. The enhancement would be the error message change, which makes this a very low prio change IMO. |
wesleytodd
left a comment
There was a problem hiding this comment.
Leaving as a comment since @jonchurch has a blocking review. But once those are changed consider this a ✅ from me.
| res.sendStatus = function sendStatus(statusCode) { | ||
| if (typeof statusCode !== 'number') { | ||
| throw new TypeError('Invalid status code: ' + statusCode); | ||
| } |
There was a problem hiding this comment.
Agreed with @jonchurch, move this to res.status, but throwing for BigInt is the right way to go.
| request(app) | ||
| .get('/') | ||
| .expect(500, /TypeError.*Invalid status code/, done) | ||
| }) |
There was a problem hiding this comment.
This test will need to move to res.status.js after the other change.
Vedant224
commented
Dec 13, 2025
@jonchurch@wesleytodd I've updated the PR to address the feedback. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
bjohansebas
left a comment
There was a problem hiding this comment.
LGTM, thanks!
Good catch, team.
bigint to res.status.
Fixes#6756
This PR adds type validation to
res.sendStatus()to prevent uncaught TypeError when BigInt values are passed as status codes.Problem:
res.sendStatus(200n)caused uncaught"Do not know how to serialize a BigInt"errorsendStatus()calledthis.status()which internally usesJSON.stringify()Solution:
sendStatus()methodTypeError: Invalid status codefor non-number inputsChanges:
lib/response.jstest/res.sendStatus.jsTesting: