-
Notifications
You must be signed in to change notification settings - Fork 27
Error handling #173
Comments
Can you give some examples of that?
I think it's important to acknowledge that there is no difference between a user model throwing an This is similar to programmer/operational errors - it depends on who is consuming the error and not who is producing it for the decision. |
The closest thing we have so far is the effort to migrate all errors to our Aside from migrating the codes, I've been exploring the possibility of adding a new I'm working through this incrementally because just the process of converting to the |
I am a bit lost by the definition of middleware (as I think it means Express middlewere) here, and the fact that we are just focusing only on HTTP in your description. Node is used for all sort of purposes, so we should think more generically for this problem. The high-level description is also missing logging as 1st class concern. How the |
@mcollina You're right, apologies, that is confusing. I've never gotten used to how "Express middleware" uses that word. To me that's not middleware. I meant it in the more traditional sense: an architecture or framework around which you build your software. Like LoopBack for example. |
Those are not exposed to userland, are they? |
boom is also a very popular library for Error handling that goes into this direction for the Hapi ecosystem. |
Interesting, pinging boom's @hueniverse to see if they have anything to add.
But a |
Not sure what I can add to this conversation. I am not following what the actual need/proposal here is. |
@ronkorving I know this issue is relatively recent, but I'm going to close it because recent governance changes make this repository obsolete. Feel free to re-open in another repository (maybe this one should go in the main node repo?) and link back to this issue so people have context. I'm sorry for the inconvenience. |
Hi everyone,
Following nodejs/node#15057, @benjamingr suggested I open an issue with the CTC regarding error handling. I am not sure if the solution of this lies in Node core, or in the bigger Node community.
It seems to me that for the user, errors can originate in these distinct areas:
The application developer only really controls the last one, but communication about errors to the end-user will often require a "code to human language"-translation. There are two ways that communication may happen:
Having a middleware take care of this is very appealing, because it can offer some guarantees that application code would not systematically have.
Regardless, a developer has to make a choice which errors are sent to the user, and in what shape. We will often want to log all stack traces, in which case that is the easy part. But when we want to send an error code to the user, we have some choices to make, with regards to which errors' codes we even want to consider. So how do we handle the errors the user should care about? (all other errors could fall back to a "generic server error" communication to the user)
MyError
class, which will be the only error type considered (instanceof
or magic.isMyError
property test)..code
) when it's there.error-type-testing
instanceof
requires an error class to be public, which is often not the case (including Node's error classes)assert
module, but not when an assertion failed in Node).special properties
.code
(or whatever name the user may end up using) can inevitably come from anywhere. It's hard to make any guarantees about unique naming. If it didn't come from the right source, it may expose sensitive information to userland..message
. If we were to use.message
instead of.code
, we risk even more sensitive information leaking to userland.wrapping all errors into one error class
This is like Joyent's verror module. I actually think it comes closest to solving the issue. When a developer uses a middleware, that middleware will have to be verror-aware, and the developer themselves will have to use verror to wrap every single error that may originate from userland (the only thing missing there seems to be a distinct error code property to translate into human readable, as that more easily allows for localization). I think the challenge here is that its successful use depends heavily on a developer's discipline to use this everywhere. It also requires the developer to use an assertion library that throws VError objects, and for that assertion library to accept error-codes from the developer (not just human readable messages).
It seems to me (but I'm just one person) that the number of obvious, elegant solutions to the problem of error communication is roughly zero (although VError comes close). This problem is of course also not unique to Node. But I'm wondering what kind of ideas the bright minds of the community may have about dealing with this issue to solve all challenges for a large group of users. Is there any really elegant approach to this? Is there anything that can be done within Node core, perhaps by making something rather "official" for errors, that modules, middleware, and assertion libraries can embrace?
Thank you for your time.
The text was updated successfully, but these errors were encountered: