standard_circuit 0.1.0 → 0.1.2

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: 2faee952d1a2a7a131f721af4ac58ce46cbbe94dadc50cd50d4e6ac24af08600
4
- data.tar.gz: e20f8adb374398ad0fab643b6333e329b6c7f5e187fc927092b1d167b4e290f8
3
+ metadata.gz: e92eb79ddb1cfc0f2e9221aa62f45d7c304df0dfea22c114eb31a78c071b6c3c
4
+ data.tar.gz: 0aac1e3c093805ea2825cfb434840d83842999cb757cdcca896466c86a6abbff
5
5
  SHA512:
6
- metadata.gz: '09dd4b8be7afd25bb06044c3b80d41fa39c302ccbb9357cd770127050af30d517cef73d8f6ad03a6112f837ae5d6a278068bc7edc147824403081afe63670f13'
7
- data.tar.gz: ef93377225b985b979ee54f35d86f9e52354030d0c5cad2131653828ee3a767239206268eb0b18b776b3ec3fa3cfc69fc9d9ed8118a9cd53ca0e9eb74cc6c834
6
+ metadata.gz: 9e5ac3bb1d7352c6300fa70530602910dd3a45539e1cfad5d45b8ac702a223a22961cdaef377daf7c968ad7bbb5db54814c70a40b1a054a41df88c15fc5908c2
7
+ data.tar.gz: e8f4b265dd59f67442b52fafdb4db15923236df241b4296adc80bb6576654a888cdc564a5c2aa36e9ad291f5720f0c7fae7a274edcce046bb6995b6fbcb04dc7
data/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.1.2] - 2026-04-27
8
+
9
+ ### Added
10
+ - `StandardCircuit::ErrorTaxonomies::{Stripe,Smtp,Aws,Faraday}.tracked` — pre-combined `NetworkErrors.defaults + AdapterErrors::X.server_errors` arrays. Saves consumers from typing the same line for every circuit they register and gives a single place to evolve what counts as a "server-side outage" per integration. `caller_errors` (validation/auth/etc.) stay on `AdapterErrors::*` because the right `skipped_errors` set is usually app-specific.
11
+
12
+ ### Changed
13
+ - `ControllerSupport.circuit_open_fallback` now appends a fresh `rescue_from Stoplight::Error::RedLight` handler each time it's called (deduplicating any prior RedLight handler on the class first, so repeated calls don't accumulate). Rails matches `rescue_handlers` last-declared-first, so a `rescue_from StandardError` catch-all declared *after* `include StandardCircuit::ControllerSupport` previously shadowed the gem's RedLight handler. As long as `circuit_open_fallback` is called after any catch-all rescues in your controller, RedLight now keeps routing to `handle_circuit_open` reliably.
14
+
15
+ ## [0.1.1] - 2026-04-27
16
+
17
+ ### Fixed
18
+ - `Mailer::Railtie`'s `standard_circuit.action_mailer` initializer now declares `before: "action_mailer.set_configs"`. Without this hint, the on_load callback that defines `standard_circuit_settings=` ran *after* Rails' `set_configs` initializer tried to forward `config.action_mailer.standard_circuit_settings = {...}` to `ActionMailer::Base`, raising `NoMethodError: undefined method 'standard_circuit_settings='` during eager_load. Two consumers previously worked around this by mutating the Initializer's private `@before` field in their `application.rb`; that workaround can now be removed.
19
+
7
20
  ## [0.1.0] - 2026-04-27
8
21
 
9
22
  ### Fixed
@@ -14,6 +14,14 @@ module StandardCircuit
14
14
  end
15
15
 
16
16
  class_methods do
17
+ # Rails iterates `rescue_handlers` from last-declared to first to find a
18
+ # match, so a `rescue_from StandardError` declared *after* `include
19
+ # StandardCircuit::ControllerSupport` shadows the gem's `RedLight` handler
20
+ # registered in `included`. Re-appending the handler here makes the DSL
21
+ # call effectively bump it to the end of the list — so as long as
22
+ # `circuit_open_fallback` is the last thing in your controller (or at
23
+ # least after any `rescue_from StandardError`-style catch-alls),
24
+ # `Stoplight::Error::RedLight` keeps routing to `handle_circuit_open`.
17
25
  def circuit_open_fallback(status: :service_unavailable, html: nil, json: nil, stream: nil)
18
26
  self._circuit_open_fallback = {
19
27
  status: status,
@@ -21,6 +29,19 @@ module StandardCircuit
21
29
  json: json,
22
30
  stream: stream
23
31
  }
32
+
33
+ # Drop existing RedLight handlers on this class before re-appending so
34
+ # repeated DSL calls (or sub-controllers calling the DSL after a base
35
+ # controller did) don't accumulate duplicate entries in
36
+ # `rescue_handlers`. Use the writer (not `reject!`) to avoid mutating
37
+ # the array a parent class might still share via `class_attribute`.
38
+ # Each entry's first element is a class-name string
39
+ # ("Stoplight::Error::RedLight"), not the constant itself.
40
+ self.rescue_handlers = rescue_handlers.reject { |handler| handler.first == "Stoplight::Error::RedLight" }
41
+
42
+ rescue_from Stoplight::Error::RedLight do |error|
43
+ handle_circuit_open(error)
44
+ end
24
45
  end
25
46
  end
26
47
 
@@ -0,0 +1,43 @@
1
+ module StandardCircuit
2
+ # Pre-combined `tracked_errors` sets per adapter — saves consumers from
3
+ # typing the same `NetworkErrors.defaults + AdapterErrors::X.server_errors`
4
+ # line for every circuit they register, and gives a single place to evolve
5
+ # what counts as a "server-side outage" for each integration.
6
+ #
7
+ # Each adapter's `tracked` returns a fresh array, so callers can safely
8
+ # `+` additional app-specific error classes without mutating shared state.
9
+ #
10
+ # Example:
11
+ # c.register(:stripe,
12
+ # tracked_errors: StandardCircuit::ErrorTaxonomies::Stripe.tracked,
13
+ # skipped_errors: StandardCircuit::AdapterErrors::Stripe.caller_errors)
14
+ #
15
+ # Adapter-specific `caller_errors` (validation/auth/etc.) stay on
16
+ # `AdapterErrors::*` because the right `skipped_errors` set is usually
17
+ # app-specific and a shared taxonomy would over-skip.
18
+ module ErrorTaxonomies
19
+ module Stripe
20
+ def self.tracked
21
+ NetworkErrors.defaults + AdapterErrors::Stripe.server_errors
22
+ end
23
+ end
24
+
25
+ module Smtp
26
+ def self.tracked
27
+ NetworkErrors.defaults + AdapterErrors::Smtp.server_errors
28
+ end
29
+ end
30
+
31
+ module Aws
32
+ def self.tracked
33
+ NetworkErrors.defaults + AdapterErrors::Aws.server_errors
34
+ end
35
+ end
36
+
37
+ module Faraday
38
+ def self.tracked
39
+ NetworkErrors.defaults + AdapterErrors::Faraday.server_errors
40
+ end
41
+ end
42
+ end
43
+ end
@@ -66,7 +66,10 @@ module StandardCircuit
66
66
  mailer_class.add_delivery_method :standard_circuit, StandardCircuit::Mailer::DeliveryMethod
67
67
  end
68
68
 
69
- initializer "standard_circuit.action_mailer" do
69
+ # `before:` ensures `add_delivery_method` (which defines the
70
+ # `standard_circuit_settings=` accessor) runs before Rails' set_configs
71
+ # tries to forward `config.action_mailer.standard_circuit_settings=`.
72
+ initializer "standard_circuit.action_mailer", before: "action_mailer.set_configs" do
70
73
  ActiveSupport.on_load(:action_mailer) do
71
74
  StandardCircuit::Mailer::Railtie.install(self)
72
75
  end
@@ -1,3 +1,3 @@
1
1
  module StandardCircuit
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -8,6 +8,7 @@ require "standard_circuit/adapter_errors/stripe"
8
8
  require "standard_circuit/adapter_errors/aws"
9
9
  require "standard_circuit/adapter_errors/faraday"
10
10
  require "standard_circuit/adapter_errors/smtp"
11
+ require "standard_circuit/error_taxonomies"
11
12
  require "standard_circuit/notifiers/logger"
12
13
  require "standard_circuit/notifiers/sentry"
13
14
  require "standard_circuit/notifiers/metrics"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_circuit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaryl Sim
@@ -87,6 +87,7 @@ files:
87
87
  - lib/standard_circuit/adapter_errors/stripe.rb
88
88
  - lib/standard_circuit/config.rb
89
89
  - lib/standard_circuit/controller_support.rb
90
+ - lib/standard_circuit/error_taxonomies.rb
90
91
  - lib/standard_circuit/health.rb
91
92
  - lib/standard_circuit/health_controller.rb
92
93
  - lib/standard_circuit/mailer/circuit_open_error.rb