Skip to content

Commit 41b0c1a

Browse files
author
Kit (OpenClaw)
committed
Add Rails error reporting audit coverage
1 parent d2e93e6 commit 41b0c1a

2 files changed

Lines changed: 94 additions & 4 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
require 'test_helper'
2+
3+
module Workarea
4+
class ErrorReportingTest < TestCase
5+
class ReporterDouble
6+
attr_reader :calls
7+
8+
def initialize(raises: false)
9+
@raises = raises
10+
@calls = []
11+
end
12+
13+
def report(error, handled:, severity:, context:)
14+
raise StandardError, 'reporter failure' if @raises
15+
16+
@calls << {
17+
error: error,
18+
handled: handled,
19+
severity: severity,
20+
context: context
21+
}
22+
23+
:reported
24+
end
25+
end
26+
27+
def test_report_forwards_to_rails_error_when_available
28+
error = StandardError.new('boom')
29+
reporter = ReporterDouble.new
30+
31+
Rails.stub(:error, reporter) do
32+
result = Workarea::ErrorReporting.report(
33+
error,
34+
handled: true,
35+
severity: :warning,
36+
context: { service: 'rubygems.org' }
37+
)
38+
39+
assert_equal(:reported, result)
40+
assert_equal(1, reporter.calls.length)
41+
assert_equal(error, reporter.calls.first[:error])
42+
assert_equal(true, reporter.calls.first[:handled])
43+
assert_equal(:warning, reporter.calls.first[:severity])
44+
assert_equal({ service: 'rubygems.org' }, reporter.calls.first[:context])
45+
end
46+
end
47+
48+
def test_report_returns_nil_when_rails_error_is_unavailable
49+
error = StandardError.new('boom')
50+
51+
Rails.stub(:error, nil) do
52+
assert_nil(Workarea::ErrorReporting.report(error))
53+
end
54+
end
55+
56+
def test_report_swallows_reporter_failures
57+
error = StandardError.new('boom')
58+
reporter = ReporterDouble.new(raises: true)
59+
60+
Rails.stub(:error, reporter) do
61+
assert_nil(Workarea::ErrorReporting.report(error))
62+
end
63+
end
64+
end
65+
end

docs/rails7-migration-patterns/error-reporting.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ This is implemented by `ActiveSupport::ErrorReporter` and is intended to be
88
**configured by the host application** (or an integration gem) to forward handled
99
exceptions to a provider (Sentry, Bugsnag, Honeybadger, etc.).
1010

11-
## Verification status (WA-VERIFY-044)
11+
## Verification status (WA-VERIFY-114)
1212

13-
**Status: ✅ Complete — implemented and compatible.**
13+
**Status: ✅ Complete — audited and compatible.**
1414

1515
Workarea implements `Workarea::ErrorReporting` as a thin wrapper around
1616
`Rails.error.report`. The wrapper is availability-guarded so it degrades
@@ -23,6 +23,23 @@ Workarea **does not ship with a bundled error reporting provider**.
2323
Instead, Workarea relies on the host application to configure an error reporting
2424
solution at the Rack / Rails level.
2525

26+
## Audited integration points
27+
28+
The audit found a small, additive integration surface only:
29+
30+
- `core/lib/workarea/error_reporting.rb` provides `Workarea::ErrorReporting`, a
31+
compatibility wrapper around `Rails.error.report`.
32+
- `core/lib/workarea/latest_version.rb`,
33+
`core/lib/workarea/ping_home_base.rb`, and
34+
`core/app/models/workarea/checkout/fraud/analyzer.rb` use that wrapper for
35+
handled exceptions that Workarea intentionally rescues.
36+
- `storefront/app/controllers/workarea/storefront/errors_controller.rb` sets
37+
`request.env['rack.exception']` for 500 responses so Rack-level reporters can
38+
observe unhandled exceptions through the normal middleware path.
39+
40+
No additional `ActiveSupport::ErrorReporter` subscribers, custom Rails error
41+
reporter configuration, or provider-specific integrations are present in core.
42+
2643
Examples:
2744

2845
- Storefront error pages set `request.env['rack.exception']` in
@@ -51,15 +68,23 @@ Host applications can configure Rails' error reporter via `config.error_reporter
5168

5269
## Decision
5370

54-
**Adopted Rails 7.1's error reporting API as an additive, opt-in hook:**
71+
**Rails 7.1's error reporting APIs do not introduce a compatibility break for
72+
Workarea internals or extension points.**
5573

5674
- Workarea calls `Rails.error.report` **only when available**.
5775
- Workarea does not require any provider.
58-
- Existing error handling continues to work unchanged.
76+
- Existing error handling and Rack-based reporting continue to work unchanged.
77+
- Extension points remain stable because host applications and plugins can opt
78+
into `config.error_reporter` without needing Workarea-specific changes.
5979

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

83+
## Client impact
84+
85+
**None expected.** Existing applications, plugins, and downstream integrations do
86+
not need code changes to remain compatible.
87+
6388
## Verification commands
6489

6590
```bash

0 commit comments

Comments
 (0)