hanami / controller

Complete, fast and testable actions for Rack and Hanami

Home Page:http://hanamirb.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disable rack logging when handle_exceptions = false or other field

absrd opened this issue · comments

I'm working on an application where we handle exceptions without Hanami::Controller's exception handler framework. Thus we've set handle_exceptions = false, but the exceptions are still logged by Hanami to Rack, unless we call handle_exception to each possible error such that they'll be added to the handled_exceptions hash. (v0.7.x)

We can disable logging with "handle_exception StandardError => 123" in later versions, but this feels hackish and will probably confuse later developers on the project.

Could we disable the logging with handle_exceptions = false or by some other new configuration field?

@absrd Hi, can you please tell me exactly which version of hanami-controller are you using? It's only hanami-controller or Hanami full stack?

What do you mean by "still logged by Hanami to Rack"? Do you mean env['rack.exception']?

@jodosha 0.7.1 hanami-controller. We're also using other Hanami gems, but not the whole stack.

The problem is that this code runs:
https://github.com/hanami/controller/blob/master/lib/hanami/action/throwable.rb#L153
, even though configuration.handle_exceptions = false has been set.

The problem lies in that above mentioned method's guard clause is only done with: configuration.handled_exception?(exception)
, which check whether precautions for the exceptions has been made with the handle_exception method, which we don't use, especially when configuration.handle_exceptions = false.

Having to define "handle_exception SomeError => xxx" in our actions, just so that the logger isn't called is hackish and will only lead to confusion.

@absrd Why env['rack.exception'] is a problem for you? That is a de-facto standard used by all the exceptions tracker SaaS (eg. BugSnag).

It's filled when the server crashes (Error 500) and you need to track what happened.


The handle_exceptions setting is used to show or not the stack trace to the user.

@absrd Why env['rack.exception'] is a problem for you? That is a de-facto standard used by all the exceptions tracker SaaS (eg. BugSnag).

That isn't the problem.

To be exact this is the problem:
https://github.com/hanami/controller/blob/master/lib/hanami/action/throwable.rb#L158

It logs to rack logger any exception made by actions if they have not been handled using the controllers' handle_exception method:
https://github.com/hanami/controller/blob/master/lib/hanami/action/throwable.rb#L154

The handle_exceptions setting is used to show or not the stack trace to the user.

, but it also turns off the exception handling in hanami actions:
https://github.com/hanami/controller/blob/master/lib/hanami/action/throwable.rb#L173

@absrd It's since a few days that I'm back to this issue over and over, trying to debug and understand all the implications of the possible scenarios.

If exceptions are NOT handled, that means the action won't suppress it. If an exception is raised, then it should be logged in env['rack.errors'].


May I ask you what are you trying to achieve? Thanks.

@jodosha We're handling exceptions higher up in the stack. Our stack consists of several Hanami applicatons that we propagate to from the root of the stack. Those several Hanami applications have similar exceptions and are thus handled centrally. Any exception that we don't handle is logged manually to a custom logger.

We only want logs from rack whenever the startup configuration fails.

I'm closing this as we can't take action w/o breaking the existing behavior.