You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Inspired by expressjs/express#2896, but proposed here because as a breaking change it likely won't make it into Express 4.0 anyway, and Express 5.0 references this.
Instead of using the number of arguments to differentiate between error and normal handlers, is there any reason not to use named functions? Example:
And then just check for this.name instead of fn.length in layer.js:63.
Should work in all places where error handlers can be specified here and in express unless I'm overlooking something, and would remove the need (and warnings) for unused parameters.
Could even still allow the old style (but make it deprecated?) to not to break existing code.
Thoughts? :)
The text was updated successfully, but these errors were encountered:
Personally, named functions are even more error prone than checking arrity. There's no advantage to the change. Also, it's pretty common to have an error handler that still passes on to next so we'd still need to handle three arguments. If there were to be a change to error handling, I'd suggest it uses less magic and not more.
It's probably also worth noting that this proposal would be incompatible with inline arrow functions. Right now the only way to get the name property set is through a previous assignment statement.
Inspired by expressjs/express#2896, but proposed here because as a breaking change it likely won't make it into Express 4.0 anyway, and Express 5.0 references this.
Instead of using the number of arguments to differentiate between error and normal handlers, is there any reason not to use named functions? Example:
Instead, we could say:
And then just check for
this.name
instead offn.length
in layer.js:63.Should work in all places where error handlers can be specified here and in express unless I'm overlooking something, and would remove the need (and warnings) for unused parameters.
Could even still allow the old style (but make it deprecated?) to not to break existing code.
Thoughts? :)
The text was updated successfully, but these errors were encountered: