Capturing an idea we've talked about offline.
It would be great to move to using (and documenting) explicit error codes for errors that express itself generates, to allow folks to use them as a contract if they wish. That would free us up from having to worry that someone is matching on error messages themselves, and therefore making error messages part of the semver contract with users.
to jog memories, this came up recently when discussing #6756
We don't have all that many tbh, but here's a table I had claude make w/ sites where we generate an error:
| File |
Line |
Error |
Proposed Code |
| response.js |
67 |
Invalid status code: ... Status code must be an integer. |
ERR_INVALID_STATUS_CODE |
| response.js |
71 |
Invalid status code: ... must be greater than 99 and less than 1000. |
ERR_STATUS_CODE_OUT_OF_RANGE |
| response.js |
386 |
path argument is required to res.sendFile |
ERR_MISSING_ARG |
| response.js |
390 |
path must be a string to res.sendFile |
ERR_INVALID_ARG_TYPE |
| response.js |
400 |
path must be absolute or specify root to res.sendFile |
ERR_INVALID_PATH |
| response.js |
681 |
Content-Type cannot be set to an Array |
ERR_INVALID_ARG_TYPE |
| response.js |
755 |
cookieParser("secret") required for signed cookies |
ERR_COOKIE_SECRET_REQUIRED |
| response.js |
936 |
Request aborted |
ERR_REQUEST_ABORTED |
| response.js |
946 |
EISDIR, read |
ERR_EISDIR |
| request.js |
66 |
name argument is required to req.get |
ERR_MISSING_ARG |
| request.js |
70 |
name must be a string to req.get |
ERR_INVALID_ARG_TYPE |
| utils.js |
148 |
unknown value for etag function |
ERR_INVALID_OPTION |
| utils.js |
180 |
unknown value for query parser function |
ERR_INVALID_OPTION |
| view.js |
61 |
No default engine was specified... |
ERR_NO_VIEW_ENGINE |
| view.js |
84 |
Module "..." does not provide a view engine. |
ERR_INVALID_VIEW_ENGINE |
| application.js |
213 |
app.use() requires a middleware function |
ERR_INVALID_MIDDLEWARE |
| application.js |
296 |
callback function required |
ERR_MISSING_CALLBACK |
| application.js |
562 |
Failed to lookup view "..." |
ERR_VIEW_NOT_FOUND |
Fastify does this quite well already: https://fastify.dev/docs/latest/Reference/Errors/
Capturing an idea we've talked about offline.
It would be great to move to using (and documenting) explicit error codes for errors that express itself generates, to allow folks to use them as a contract if they wish. That would free us up from having to worry that someone is matching on error messages themselves, and therefore making error messages part of the semver contract with users.
to jog memories, this came up recently when discussing #6756
We don't have all that many tbh, but here's a table I had claude make w/ sites where we generate an error:
Invalid status code: ... Status code must be an integer.ERR_INVALID_STATUS_CODEInvalid status code: ... must be greater than 99 and less than 1000.ERR_STATUS_CODE_OUT_OF_RANGEpath argument is required to res.sendFileERR_MISSING_ARGpath must be a string to res.sendFileERR_INVALID_ARG_TYPEpath must be absolute or specify root to res.sendFileERR_INVALID_PATHContent-Type cannot be set to an ArrayERR_INVALID_ARG_TYPEcookieParser("secret") required for signed cookiesERR_COOKIE_SECRET_REQUIREDRequest abortedERR_REQUEST_ABORTEDEISDIR, readERR_EISDIRname argument is required to req.getERR_MISSING_ARGname must be a string to req.getERR_INVALID_ARG_TYPEunknown value for etag functionERR_INVALID_OPTIONunknown value for query parser functionERR_INVALID_OPTIONNo default engine was specified...ERR_NO_VIEW_ENGINEModule "..." does not provide a view engine.ERR_INVALID_VIEW_ENGINEapp.use() requires a middleware functionERR_INVALID_MIDDLEWAREcallback function requiredERR_MISSING_CALLBACKFailed to lookup view "..."ERR_VIEW_NOT_FOUNDFastify does this quite well already: https://fastify.dev/docs/latest/Reference/Errors/