Skip to content
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

Communicate #after hook errors in Middleware #1265

Closed
rngtng opened this issue Feb 1, 2016 · 10 comments
Closed

Communicate #after hook errors in Middleware #1265

rngtng opened this issue Feb 1, 2016 · 10 comments

Comments

@rngtng
Copy link
Contributor

rngtng commented Feb 1, 2016

As of #1240 the #after hook is called on middlewares even when exception is raised. This breaks middleware which assume response, (@app_response) is set. (e.g. grape_logging).

Firstly, any middleware should be migrated to handle this case, secondly grape should give a warning at least, to help debugging and prevent the application from hard failure.

See discussion at: #1240 (comment)

@dblock
Copy link
Member

dblock commented Feb 1, 2016

👍

@jpaas
Copy link

jpaas commented Feb 12, 2016

I am also running into this issue. My logging middleware is unable to log the response in the after hook.

@gregormelhorn
Copy link

I am currently trying to fix this issue. One thing I stumbled upon is that the formatter also uses error handling to communicate issues in the after callback.

Fortunately, from what I can see now, catch(:error) and rethrowing while swallowing any StandardError from the after callback would fix the issue - but it also alters the behaviour of the formatter. I am not sure if this should really be implemented I have to say.

I would vote for a setting to switch on and off the "rescue StandardError behaviour" in the after callback (while still keeping and rethrowing any explicitly thrown error).

What do you think?

@gregormelhorn
Copy link

The more I think about it, the more it would make sense to add a backwards compatibility switch (do not run after callbacks on error) instead of magically catching exceptions...

@dblock
Copy link
Member

dblock commented Feb 22, 2016

@gregormelhorn Maybe. That seems to undo the change we made, I'd rather not have both behaviors and issue a warning as described in this issue. But do try some code and show us what happens before/after.

@gregormelhorn
Copy link

The changes mean that any StandardError thrown gets transformed into a warning.

It also means that catching standard exceptions inside formatters is not possible, so I removed the corresponding tests. After all, the code does not care if the issue is in the after callback of a logging middleware or the after callback of a formatter.

I am still not sure if making this fail hard with exceptions is not the better way - it will be very easy to miss coding errors.

@rngtng
Copy link
Contributor Author

rngtng commented Feb 22, 2016

Ok, true a hard fail makes sense, but for debugging reason It would help a lot to know that the error happened in middleware so what about a warning + re-raise the original error?

@gregormelhorn
Copy link

ok, I changed it accordingly 👍

@dblock
Copy link
Member

dblock commented Feb 22, 2016

Closed via #1285.

@dblock dblock closed this as completed Feb 22, 2016
@rngtng
Copy link
Contributor Author

rngtng commented Feb 22, 2016

nice, thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants