standard_ledger 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddedb70c2937f7108178cce27f7150b58c39c5aadfdab2561947b626bd345d9c
4
- data.tar.gz: be910d616703d17691bdc6f184247b5efe78bc959006c24f43ee4bfbeb5df263
3
+ metadata.gz: cd7ecc82e5bc8d3f7eb9a8d43cbadf1d3fa1180f42fe157081d61d182a022787
4
+ data.tar.gz: 4d35b483d9139d20aaa18affc838beb60b3e791f0ef6bd3b8d3cbdc35e2a1c15
5
5
  SHA512:
6
- metadata.gz: 1bd764a4596fb6468f5ffa9b2d51e39a5203f6135bbdbde6cacec33091aa0e86cedaa1393392f417378a720f6e26987438c8a46fc80028204ecf0250ed3a7c49
7
- data.tar.gz: 829aad11a875317df036555736281f0ca6d961045bd3a5b2dd6090592ce0aabce772583b34d7fd403c69a4f331bb11f46e6a9622ccc62f510fb0574dea8bd85a
6
+ metadata.gz: be20b42b99109406f022c62fb4265e47bad5c2b5c620e94c97475c003859a6be53aa4f46c663f3b518dfb957cf9249638e275eaf4a5278ffad0d01025fd30091
7
+ data.tar.gz: '0634709547f626bf6ef39ebeb0b6032254fc1093035dcd57f7fcc994a5ba7a06d339413dd77aa29b26a84b28f424b1cee410f678ef3ea5f1077563ead09bfa42'
data/CHANGELOG.md CHANGED
@@ -6,6 +6,41 @@ project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.9.0] - 2026-11-23
10
+
11
+ ### Added
12
+
13
+ - **`Config#error_reporter`**: an optional callable `(error, context)` that
14
+ receives the errors the gem reports (a failed `refresh!`, re-raised after
15
+ reporting, and a failing `concurrently: :auto` catalog probe, handled). The
16
+ context is the site's Hash (`view:`, plus `concurrently:` for a failed
17
+ refresh) merged with `source: "standard_ledger"`, `handled:` and `severity:`.
18
+ nil (the default) keeps the existing `Rails.error.report` /
19
+ `ActiveSupport.error_reporter` behaviour unchanged. Both sites already went
20
+ through `StandardLedger.report_error`, which now checks the setting first.
21
+ A raising reporter is still swallowed and never masks the original error.
22
+
23
+ ## [0.8.0] - 2026-10-28
24
+
25
+ ### Fixed
26
+
27
+ - **An idempotent replay inside a host transaction no longer poisons it on
28
+ Postgres.** `create!` now inserts inside a savepoint
29
+ (`transaction(requires_new: true)`), so a duplicate idempotency key rolls back
30
+ only that INSERT. Before, the failed INSERT aborted the host's whole
31
+ transaction and the rescue's `find_by` raised `PG::InFailedSqlTransaction`,
32
+ as did every later statement in it. Covered by a deterministic duplicate and
33
+ a two-connection race on the new Postgres CI leg.
34
+
35
+ ### Changed
36
+
37
+ - **The suite also runs on PostgreSQL in CI** (`test (postgres)`). Set
38
+ `DATABASE_URL` to a database whose name contains `test` to run it locally;
39
+ the dummy schema is loaded with `force: true`.
40
+
41
+ - **Requires Rails 8.1** (`railties`, `activerecord`, `activesupport` `>= 8.1`,
42
+ was `>= 8.0`). Every consumer app runs 8.1; 8.0 was never exercised in CI.
43
+
9
44
  ## [0.7.0] - 2026-09-24
10
45
 
11
46
  The Phase 4 release. The removals the cleanup plan scheduled for it (the
data/README.md CHANGED
@@ -140,6 +140,21 @@ failure is reported once. Input errors (an invalid view name, an unknown
140
140
  and are not reported by the gem. View names must be bare or `schema.view`
141
141
  identifiers. Anything else raises `ArgumentError`.
142
142
 
143
+ Both reports go to `Config#error_reporter` instead when it is set, a callable
144
+ taking `(error, context)`. The context is the site's Hash merged with
145
+ `source: "standard_ledger"`, `handled:` and `severity:`, so the reporter can
146
+ tell the re-raised refresh failure from the handled probe failure:
147
+
148
+ ```ruby
149
+ StandardLedger.configure do |c|
150
+ c.error_reporter = ->(error, context) { Sentry.capture_exception(error, extra: context) }
151
+ end
152
+ ```
153
+
154
+ It replaces the `Rails.error` call. Rails' dedupe does not apply to a custom
155
+ reporter, so keep no report-and-re-raise rescue of your own around `refresh!`.
156
+ A reporter that raises is swallowed and never masks the original error.
157
+
143
158
  ## Installation
144
159
 
145
160
  ```ruby
@@ -32,6 +32,15 @@ StandardLedger.configure do |c|
32
32
  # <prefix>.projection.failed
33
33
  # c.notification_namespace = "standard_ledger"
34
34
 
35
+ # ---------------------------------------------------------------------------
36
+ # Error reporting
37
+ # ---------------------------------------------------------------------------
38
+
39
+ # Where a failed refresh! (re-raised) and a failing :auto catalog probe
40
+ # (handled) are reported. Default nil: Rails.error.report. The context Hash
41
+ # carries the site's keys plus source:, handled: and severity:.
42
+ # c.error_reporter = ->(error, context) { Sentry.capture_exception(error, extra: context) }
43
+
35
44
  # ---------------------------------------------------------------------------
36
45
  # Host Result interop
37
46
  # ---------------------------------------------------------------------------
@@ -32,11 +32,32 @@ module StandardLedger
32
32
  # `<prefix>.projection.failed`.
33
33
  attr_accessor :notification_namespace
34
34
 
35
+ # Optional: where the gem sends the errors it reports — a failed
36
+ # `refresh!` (re-raised after reporting) and a failing `:auto` catalog
37
+ # probe (handled; the refresh runs plain). A callable taking
38
+ # `(error, context)`. `context` is the site's Hash (`view:`, plus
39
+ # `concurrently:` for a failed refresh) merged with
40
+ # `source: "standard_ledger"`, `handled:` and `severity:`, so a reporter
41
+ # can tell the re-raised refresh error from the handled probe failure.
42
+ #
43
+ # nil (the default) means `Rails.error.report` (or
44
+ # `ActiveSupport.error_reporter` outside Rails) with `handled:`,
45
+ # `severity:` and `source: "standard_ledger"` as keywords:
46
+ #
47
+ # c.error_reporter = ->(error, context) { Sentry.capture_exception(error, extra: context) }
48
+ #
49
+ # It replaces the Rails.error call. Rails.error's dedupe (it skips an
50
+ # exception it has already reported) does not apply to a custom reporter,
51
+ # so a host that also reports the re-raised refresh error sees it twice.
52
+ # A reporter that raises is swallowed and never masks the original error.
53
+ attr_accessor :error_reporter
54
+
35
55
  def initialize
36
56
  @matview_refresh_strategy = :concurrent
37
57
  @result_class = nil
38
58
  @result_adapter = nil
39
59
  @notification_namespace = "standard_ledger"
60
+ @error_reporter = nil
40
61
  end
41
62
 
42
63
  # True when the host has wired up its own Result type. When false, the gem
@@ -80,7 +80,13 @@ module StandardLedger
80
80
 
81
81
  validate_standard_ledger_idempotency_index!
82
82
 
83
- super
83
+ # A savepoint, so a duplicate rolls back only this INSERT. Hosts post
84
+ # inside their own transaction, and on Postgres a failed statement
85
+ # aborts the whole transaction: without it the find_by below, and
86
+ # every later statement in the host's transaction, raises
87
+ # PG::InFailedSqlTransaction. With no outer transaction this is the
88
+ # same single transaction create! would open anyway.
89
+ transaction(requires_new: true) { super(attributes, &block) }
84
90
  rescue ActiveRecord::RecordNotUnique => e
85
91
  raise unless standard_ledger_idempotency_violation?(e)
86
92
 
@@ -1,3 +1,3 @@
1
1
  module StandardLedger
2
- VERSION = "0.7.0"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -137,12 +137,18 @@ module StandardLedger
137
137
  )
138
138
  end
139
139
 
140
- # Report +error+ through `Rails.error` (or `ActiveSupport.error_reporter`
141
- # outside Rails) with `source: "standard_ledger"`. A reporter failure is
142
- # swallowed so it can never mask the error being reported.
140
+ # Report +error+ through `Config#error_reporter` when set, otherwise
141
+ # `Rails.error` (or `ActiveSupport.error_reporter` outside Rails) with
142
+ # `source: "standard_ledger"`. A reporter failure is swallowed so it can
143
+ # never mask the error being reported.
143
144
  #
144
145
  # @api private
145
146
  def report_error(error, handled:, severity:, context:)
147
+ if (custom = config.error_reporter)
148
+ custom.call(error, { **context, source: "standard_ledger", handled: handled, severity: severity })
149
+ return
150
+ end
151
+
146
152
  reporter =
147
153
  if defined?(::Rails) && ::Rails.respond_to?(:error)
148
154
  ::Rails.error
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_ledger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
- - Jaryl Sim
7
+ - Rarebit One
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
@@ -15,42 +15,42 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '8.0'
18
+ version: '8.1'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: '8.0'
25
+ version: '8.1'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activerecord
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '8.0'
32
+ version: '8.1'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '8.0'
39
+ version: '8.1'
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: activesupport
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '8.0'
46
+ version: '8.1'
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '8.0'
53
+ version: '8.1'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: brakeman
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 4.0.3
146
+ rubygems_version: 4.0.20
147
147
  specification_version: 4
148
148
  summary: Immutable, append-only journal entries and materialized-view refresh for
149
149
  Rails apps.