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
There are many places in the code where `StandardError` is rescued and
the exception is reported to Sentry using `Sentry.capture_exception`,
but the exception itself is then swallowed. I'm not totally convinced
this is sensible even in production, because `StandardError` covers a
multitude of exception types. However, it's definitely problematic in
development and test environments where Sentry is typically not
configured, so there's no way to see what exceptions might have been
swallowed.
We still have at least one flakey spec example [1] and that calls
`SchoolTeacher::Invite.call` which includes one of the rescue blocks [2]
mentioned above. The flakey example fails when the method returns an
`OperationResponse` instance for which `OperationResponse#success?`
returns `false`. And the most obvious reason for that to happen is if
`TeacherInvitation.create!` raises an exception (e.g. because of a
validation error).
I'd like to get visibility of this exception when the example fails in a
CircleCI build. This commit patches the `Sentry.capture_exception`
method when Sentry is not configured to report errors (i.e. typically in
development and test environments) to display the exception and
stacktrace in stderr as a warning.
It might be better to add a custom error reporter module (or even use
the error reporter built into Rails [3]) and use that throughout the
code, but that would have meant widespread changes to the code, so I
think this is probably better for now to see whether it's a useful
approach.
[1]: https://github.com/RaspberryPiFoundation/editor-api/blob/f397e870f2a33cce1f53b9104c52314f5233572c/spec/concepts/school_teacher/invite_spec.rb#L14-L17
[2]: https://github.com/RaspberryPiFoundation/editor-api/blob/f397e870f2a33cce1f53b9104c52314f5233572c/lib/concepts/school_teacher/invite.rb#L10-L14
[3]: https://guides.rubyonrails.org/v7.1/error_reporting.html
0 commit comments