Skip to content

Standardize on error codes for errors express throws #6951

@jonchurch

Description

@jonchurch

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/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions