Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions core/app/models/workarea/checkout/fraud/analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ def decide!
begin
decision = make_decision.tap { |r| r.analyzer = self.class.name }
rescue => e
Workarea::ErrorReporting.report(
e,
handled: true,
severity: :warning,
context: {
analyzer: self.class.name,
order_id: order&.id,
checkout_class: checkout.class.name
}
)

decision = error_decision(e.message)
ensure
order.set_fraud_decision!(decision)
Expand Down
36 changes: 36 additions & 0 deletions core/lib/workarea/error_reporting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module Workarea
# Small wrapper around Rails 7.1+'s error reporting API.
#
# Rails.error.report is an additive mechanism which can be configured by host
# applications (or plugins) to forward handled exceptions to Sentry, Bugsnag,
# etc. Workarea itself intentionally does not hard-code a specific provider.
module ErrorReporting
class << self
# @param error [Exception]
# @param handled [Boolean] whether the exception was handled/swallowed
# @param severity [Symbol] :error, :warning, :info
# @param context [Hash] additional structured context
def report(error, handled: true, severity: :error, context: {})
return unless rails_error_reporter_available?

Rails.error.report(
error,
handled: handled,
severity: severity,
context: context
)
rescue StandardError
# Never allow error reporting failures to impact runtime behavior.
nil
end

private

def rails_error_reporter_available?
defined?(Rails) && Rails.respond_to?(:error) && Rails.error.respond_to?(:report)
end
end
end
end
7 changes: 7 additions & 0 deletions core/lib/workarea/latest_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ def self.get
JSON.parse(response.body)['version']
end
rescue Exception => e
Workarea::ErrorReporting.report(
e,
handled: true,
severity: :warning,
context: { service: 'rubygems.org', url: 'https://rubygems.org/api/v1/gems/workarea.json' }
)

Rails.logger.error '-------------------------------------'
Rails.logger.error "There was an error contacting rubygems.org!"
Rails.logger.error e.class
Expand Down
7 changes: 7 additions & 0 deletions core/lib/workarea/ping_home_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ def ping
http.start { |h| h.request(request) }

rescue Exception => e
Workarea::ErrorReporting.report(
e,
handled: true,
severity: :warning,
context: { service: 'homebase.weblinc.com', url: URL }
)

Rails.logger.error '-------------------------------------'
Rails.logger.error "There was an error contacting #{URL}!"
Rails.logger.error e.class
Expand Down
53 changes: 53 additions & 0 deletions docs/rails7-migration-patterns/error-reporting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Error reporting (Rails 7.1+)

Rails 7.1 introduced a framework-level error reporting API:

- `Rails.error.report(exception, handled:, severity:, context:)`

This is implemented by `ActiveSupport::ErrorReporter` and is intended to be
**configured by the host application** (or an integration gem) to forward handled
exceptions to a provider (Sentry, Bugsnag, Honeybadger, etc.).

## Current Workarea behavior

Workarea **does not ship with a bundled error reporting provider**.

Instead, Workarea relies on the host application to configure an error reporting
solution at the Rack / Rails level.

Examples:

- Storefront error pages set `request.env['rack.exception']` in
`Workarea::Storefront::ErrorsController#internal` so Rack middleware (and error
reporters that hook into it) can see the exception.
- Workarea has optional provider integrations via separate plugins (e.g.
`workarea-sentry`).

In core Workarea code, most exceptions are either:

- Raised normally (and therefore captured by the host app’s exception handling), or
- Rescued and logged in a few places where Workarea intentionally swallows the
error (for example: version checks / telemetry-like pings).

## Decision

**Adopt Rails 7.1’s error reporting API as an additive, opt-in hook.**

This means:

- Workarea will call `Rails.error.report` **only when available**.
- Workarea will not require any provider.
- Existing error handling continues to work unchanged.

This is useful primarily for *handled/swallowed* exceptions where otherwise the
host app may never learn about the error.

## Implementation notes

- Add `Workarea::ErrorReporting.report` as a small wrapper around
`Rails.error.report`.
- Use it in places where Workarea rescues and continues (handled errors), with
`severity: :warning` and some lightweight context.

Host applications can configure Rails’ error reporter via `config.error_reporter`
(or via a provider gem that integrates with `ActiveSupport::ErrorReporter`).
Loading