-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure Boom objects can be reused - Fix for issue #3378 #3380
Conversation
Added an additional regression test based on comments in the issue's discussion thread, see #3378. |
I think this is correct unless @hueniverse knows of a better fix. |
I'm confused – why should this be supported? Boom objects are not designed for reuse. |
Same for me, I feel that it's a bad pattern. Pre-generating errors won't improve your performance by any means (if that's the intention), and you'll lose a meaningful way of debugging, that is stacktraces. I'd favor error factories for that. |
I can agree on that, I wouldn't do it either but the way hapi handles it now does not feel correct either |
I agree with both sides– ideally I'd like to see hapi deal with this better, but booms are actual |
|
Thanks for everyone's input. Using Hapi for the last eight months has been an absolute pleasure and I haven't contributed to a project in recent memory whose community is this active. For those confused, reading the original bug discussion may aid in better understanding. To be clear for my own part, I wasn't reusing Booms in an effort to be more performant. I did it because it felt like cleaner code to have constants representing the errors that can occur above the handler. Especially in cases of plugins where affording for other developers scanning the code for meaning is important. Additionally, and I know this is unlikely to sway anyone, I would never expect a tool/framework to which I hand something to mutate that thing. It's my data, I've just given it to Hapi in order to create IO.
That's a compelling argument for Error's. I was reusing Boom objects. The fact that it happens to support proper Errors as well was mostly an accident. I was concerned about performance as well but having read Boom more carefully I think the Here is an example of common content of error.output = {
statusCode: 500,
payload: {
message: 'An internal server error occurred'
},
headers: {}
}; Again, it's not cloning the entire boom or error object. Only It's cool with me if we don't support re-use it though. If we go another route through, I would suggest figuring out a way of providing some sort or error or warning to the user since the side effect of reuse currently is that the response appears empty in several commonly used clients (Chrome and curl are the ones I've been testing with). |
What is the reason the headers are copied? For errors like unauthorized right? I do agree that hapi should not modify (boom) errors you give it. |
I'm not first and foremost concerned with performance here. The reason I'm not into supporting reuse is that boom is an At the same time, I do see how hapi hanging upon error reuse is very confusing and isn't ideal. |
Headers are added by two of Boom's errors,
Hapi doesn't actually hang. It responds with headers that don't match the content causing clients to display no output because the response body fails to decode. See my comment in the original thread. |
@wwalser I meant that by 'hanging up' ^^ I think we all agree that the use case is an anti pattern that you should not be doing but is this a bug then or not? |
A few thoughts re: is this a bug?
I feel that prescribing what should be done would be to step out of bounds as someone who has just shown up. I defer to those who have cared for and crafted Hapi for much longer than myself. Thanks for looking into the issue and PR :). |
1: agree |
I only meant that there's no need for Boom to create it's internal Error until the Boom is actually being handled by Hapi. If it instead created the Error at the time of use instead of instantiation the stack traces would be correct regardless of the way that the Booms are created, referenced, copied etc. |
Well since Boom errors are actual errors but with more info I think that would be weird but I see where you come from |
This is not the right solution, but the tests are useful. |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
Fix for #3378 Let me know when it's all clear and I'll squash.
Cheers,
Wes