rails_twirp 0.15 → 0.17

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: 4e1b6e06cf246cc4ab4a639ca805033c8f96a24d2a1f468b733001b5f4ca9732
4
- data.tar.gz: 4e03e912af4c785bbe9852245ed6e763e6d398c335dd63d4d0c4c3751402b814
3
+ metadata.gz: 4214210eff742236d7214ff558426f2dc9aed2e929b8e4ccb3c30777f5075bae
4
+ data.tar.gz: 8de1099ab7e26c27ce4c226325f7f0d535e5fe017e2fa4728e336b5293f767cb
5
5
  SHA512:
6
- metadata.gz: 6cdc2a1d80937bbb85a513cc4807e9a91c5bd0848d5b959e90d226477231387c0e9250ec30bf7ff8da170c8cf64ca7136bcd47deb3fb23206797749bdbe624b8
7
- data.tar.gz: 68c342ad35489011bc921dc4c7529d5ff7a18f47fce4aef9c597cebd2a789bdcec8050b6738cad457bcb54fce0b1c9f262558a964d42b26e1063a34f73f9d250
6
+ metadata.gz: a148e4b8363ac7eb45423eef57e98fd3d29cb10cca70ed43c178a453a1e0d6f47b17f22f061656195aa645f8afaeeaf0b58f5dcc3e637410ecb5789137d85f3d
7
+ data.tar.gz: 959f3beeac15882ad998b88733eb1f1a4f54a4d198c5293fabfe9d8c5acd583e84d9e0d32b02ef3b1d4dc9c0909b1eba537db5e62df98ec98651f9eec9ce9c0a
@@ -1,18 +1,24 @@
1
1
  name: Ruby Test
2
- on: push
2
+ on: [push]
3
3
 
4
4
  jobs:
5
5
  test:
6
+ name: Ruby Tests
6
7
  runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby: ["3.0", "3.1", "3.2", "3.3"]
12
+
7
13
  steps:
8
- - name: Checkout code
14
+ - name: Checkout
9
15
  uses: actions/checkout@v3
10
16
 
11
17
  - name: Setup Ruby
12
18
  uses: ruby/setup-ruby@v1
13
19
  with:
14
- ruby-version: 3.3.0
15
20
  bundler-cache: true
21
+ ruby-version: ${{ matrix.ruby }}
16
22
 
17
23
  - name: Run tests
18
24
  run: bin/test
data/.standard.yml CHANGED
@@ -1,3 +1 @@
1
- ignore:
2
- - '**/*':
3
- - Lint/RescueException
1
+ ruby_version: 2.7
data/CHANGELOG.md CHANGED
@@ -1,9 +1,15 @@
1
- ### 0.15.0
1
+ ### 0.17
2
+ * Adding support for rails 7.2. Mostly this was fixing the deprecation of `request.show_exceptions?` and support the various
3
+ values of `Rails.application.config.action_dispatch.show_exceptions`.
2
4
 
5
+ ### 0.16
6
+ * Ensure `decode_rack_response` always calls `#close` on the Rack body in tests, as some middleware might be applying a BodyProxy
7
+
8
+ ### 0.15
3
9
  * Exclude versions of Rails 7 which were incompatible with the pbbuilder ActionView handler, as pbbuilder cannot work there at all
4
10
  * Fix decode_rack_response to be compatible with Rack response body wrappers (and conform to the Rack SPEC)
5
11
 
6
- ### 0.14.0
12
+ ### 0.14
7
13
  * Adding frozen_string_literal: true to all files.
8
14
 
9
15
  ### 0.13.2
@@ -18,14 +24,14 @@
18
24
  * Include `ActionController::Caching` with Base controller/helpers
19
25
 
20
26
 
21
- ### 0.12.0
27
+ ### 0.12
22
28
 
23
29
  * Allow a custom exception handling proc to be assigned using `RailsTwirp.unhandled_exception_handler`
24
30
 
25
- ### 0.11.0
31
+ ### 0.11
26
32
 
27
33
  * Update configuration and tests for Rails 7 compatibility
28
34
 
29
- ### 0.10.0
35
+ ### 0.10
30
36
 
31
37
  * Handle exceptions more like the Rails controllers do it, do not capture all of them as if they were Twirp exceptions
data/Gemfile CHANGED
@@ -8,7 +8,6 @@ gemspec
8
8
  gem "sqlite3"
9
9
  gem "pbbuilder"
10
10
  gem "standard"
11
- gem "pry"
12
11
 
13
12
  # HACK(bouk): Overwrite Bundler's platform matcher to ignore universal CPU
14
13
  # The protobuf and gRPC 'universal' macOS gems break on M1
data/Rakefile CHANGED
@@ -6,8 +6,27 @@ require "rake/testtask"
6
6
 
7
7
  Rake::TestTask.new(:test) do |t|
8
8
  t.libs << "test"
9
- t.pattern = "test/**/*_test.rb"
10
- t.verbose = false
9
+ t.libs << "lib"
10
+
11
+ # Running specific tests with line numbers, like with rails test, is not supported by default in rake.
12
+ # By setting the TESTOPS env var we can however specify the name of a single test with underscores instead of spaces.
13
+ # So run your single test by calling for ex:
14
+ #
15
+ # rake test /Users/sebastian/projects/cheddar/rails-twirp/test/ping_controller_test.rb "uncaught errors should bubble up to the test"
16
+
17
+ file_name = ARGV[1]
18
+ test_name = ARGV[2]&.tr(" ", "_")
19
+
20
+ ENV["TESTOPTS"] = "--verbose"
21
+
22
+ t.test_files = if file_name
23
+ if test_name
24
+ ENV["TESTOPTS"] += " --name=test_#{test_name}"
25
+ end
26
+ [file_name]
27
+ else
28
+ FileList["test/**/*_test.rb"]
29
+ end
11
30
  end
12
31
 
13
32
  task default: :test
@@ -10,7 +10,7 @@ module RailsTwirp
10
10
 
11
11
  def process_action(*)
12
12
  super
13
- rescue Exception => e
13
+ rescue => e
14
14
  # Only the exceptions which are not captured by ActionController-like "rescue_from" end up here.
15
15
  # The idea is that any exception which is rescued by the controller is treated as part of the business
16
16
  # logic, and thus taking action on it is the responsibility of the controller which uses "rescue_from".
@@ -18,9 +18,19 @@ module RailsTwirp
18
18
 
19
19
  # We adopt the same error handling logic as Rails' standard middlewares:
20
20
  # 1. When we 'show exceptions' we make the exception bubble up—this is useful for testing
21
- # If the exception gets raised here error reporting will happen in the middleware of the APM package
21
+ # If the exception gets raised here, error reporting will happen in the middleware of the APM package
22
22
  # higher in the call stack.
23
- raise e unless http_request.show_exceptions?
23
+ #
24
+
25
+ # A backtrace cleaner acts like a filter that only shows us the backtrace
26
+ # with a selection of useful lines compared to all lines the code goes through.
27
+ backtrace_cleaner = http_request.get_header("action_dispatch.backtrace_cleaner")
28
+
29
+ # Contains various exception related methods we can use and takes the backtrace_cleaner into consideration.
30
+ exception_wrapper = ActionDispatch::ExceptionWrapper.new(backtrace_cleaner, e)
31
+ # ExceptionWrapper.show? contains the logic that chooses to pass exceptions through or not based on the
32
+ # `Rails.application.config.action_dispatch.show_exceptions` setting of :none, :rescuable and :all
33
+ raise e unless exception_wrapper.show?(http_request)
24
34
 
25
35
  # 2. We report the error to the error tracking service, this needs to be configured.
26
36
  RailsTwirp.unhandled_exception_handler&.call(e)
@@ -59,10 +59,10 @@ module RailsTwirp
59
59
  @module = nil
60
60
  end
61
61
 
62
- def service(service_definition, **, &block)
62
+ def service(service_definition, **kwargs, &block)
63
63
  service_route_set = @route_set.services[service_definition]
64
64
  service_mapper = ServiceMapper.new(service_route_set, self)
65
- scope(**) { service_mapper.instance_exec(&block) }
65
+ scope(**kwargs) { service_mapper.instance_exec(&block) }
66
66
  end
67
67
 
68
68
  def scope(**options)
@@ -9,8 +9,8 @@ module RailsTwirp
9
9
 
10
10
  def process_action(*)
11
11
  super
12
- rescue Exception => exception
13
- rescue_with_handler(exception) || raise
12
+ rescue => e
13
+ rescue_with_handler(e) || raise
14
14
  end
15
15
  end
16
16
  end
@@ -91,14 +91,17 @@ module RailsTwirp
91
91
  end
92
92
 
93
93
  def decode_rack_response(service, rpc, status, headers, body)
94
- body = Array.wrap(body).join # body is each-able
94
+ body_bytes = StringIO.new("".b)
95
+ body.each { |b| body_bytes << b }
95
96
 
96
97
  if status === 200
97
98
  output_class = service.rpcs[rpc][:output_class]
98
- Twirp::Encoding.decode(body, output_class, headers["Content-Type"])
99
+ Twirp::Encoding.decode(body_bytes.string, output_class, headers["Content-Type"])
99
100
  else
100
- Twirp::Client.error_from_response(Response.new(status, body, headers))
101
+ Twirp::Client.error_from_response(Response.new(status, body_bytes.string, headers))
101
102
  end
103
+ ensure
104
+ body.close if body.respond_to?(:close) # Comply with Rack API
102
105
  end
103
106
 
104
107
  def set_controller_from_rack_env(env)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsTwirp
4
- VERSION = "0.15"
4
+ VERSION = "0.17"
5
5
  end
data/rails_twirp.gemspec CHANGED
@@ -13,10 +13,9 @@ Gem::Specification.new do |spec|
13
13
 
14
14
  spec.files = `git ls-files`.split("\n")
15
15
 
16
- # Rails has shipped an incompatible change in ActiveView, that was reverted in later versions.
17
- # @see https://github.com/rails/rails/pull/51023
18
- excluded_versions = ["7.1.0", "7.1.1", "7.1.2", "7.1.3"].map { |v| "!= #{v}" }
19
- spec.add_runtime_dependency "rails", ">= 6.1.3", *excluded_versions
20
- spec.add_runtime_dependency "twirp", ">= 1.9", "< 1.11"
16
+ spec.add_runtime_dependency "rails", ">= 6.1.3", "!= 7.1"
17
+ spec.add_runtime_dependency "twirp", ">= 1.9"
18
+ spec.add_development_dependency "pry"
19
+
21
20
  spec.required_ruby_version = ">= 3"
22
21
  end
@@ -28,8 +28,12 @@ Rails.application.configure do
28
28
  config.action_controller.perform_caching = false
29
29
  config.cache_store = :null_store
30
30
 
31
- # Raise exceptions instead of rendering exception templates.
32
- config.action_dispatch.show_exceptions = false
31
+ # Set to one of the following (default is :all):
32
+ #
33
+ # :all - render error pages for all exceptions
34
+ # :rescuable - render error pages for exceptions declared by config.action_dispatch.rescue_responses
35
+ # :none - raise all exceptions
36
+ config.action_dispatch.show_exceptions = :none
33
37
 
34
38
  # Disable request forgery protection in test environment.
35
39
  config.action_controller.allow_forgery_protection = false
@@ -49,14 +49,16 @@ class PingControllerTest < RailsTwirp::IntegrationTest
49
49
  end
50
50
 
51
51
  test "uncaught errors should bubble up to the test" do
52
+ Rails.application.env_config["action_dispatch.show_exceptions"] = :none
53
+
52
54
  req = RPC::DummyAPI::PingRequest.new
53
55
  assert_raises StandardError, "Uncaught" do
54
56
  rpc RPC::DummyAPI::DummyService, "UncaughtError", req
55
57
  end
56
58
  end
57
59
 
58
- test "uncaught errors should return an internal error with details if show_exceptions is true" do
59
- Rails.application.env_config["action_dispatch.show_exceptions"] = true
60
+ test "uncaught errors should return an internal error with details if show_exceptions is all" do
61
+ Rails.application.env_config["action_dispatch.show_exceptions"] = :all
60
62
 
61
63
  req = RPC::DummyAPI::PingRequest.new
62
64
  rpc RPC::DummyAPI::DummyService, "UncaughtError", req
@@ -64,12 +66,10 @@ class PingControllerTest < RailsTwirp::IntegrationTest
64
66
  assert_equal :internal, response.code
65
67
  assert_equal "Uncaught", response.msg
66
68
  assert_equal "StandardError", response.meta["cause"]
67
- ensure
68
- Rails.application.env_config["action_dispatch.show_exceptions"] = false
69
69
  end
70
70
 
71
71
  test "uncaught errors should be fanned out to the exception handler proc if one is defined" do
72
- Rails.application.env_config["action_dispatch.show_exceptions"] = true
72
+ Rails.application.env_config["action_dispatch.show_exceptions"] = :all
73
73
 
74
74
  captured_exception = nil
75
75
  RailsTwirp.unhandled_exception_handler = ->(e) { captured_exception = e }
@@ -83,11 +83,10 @@ class PingControllerTest < RailsTwirp::IntegrationTest
83
83
  assert_kind_of StandardError, captured_exception
84
84
  ensure
85
85
  RailsTwirp.unhandled_exception_handler = nil
86
- Rails.application.env_config["action_dispatch.show_exceptions"] = false
87
86
  end
88
87
 
89
88
  test "uncaught errors should return an internal error without if show_exceptions is true and show_detailed_exceptions is false" do
90
- Rails.application.env_config["action_dispatch.show_exceptions"] = true
89
+ Rails.application.env_config["action_dispatch.show_exceptions"] = :all
91
90
  Rails.application.env_config["action_dispatch.show_detailed_exceptions"] = false
92
91
 
93
92
  req = RPC::DummyAPI::PingRequest.new
@@ -97,7 +96,6 @@ class PingControllerTest < RailsTwirp::IntegrationTest
97
96
  assert_equal "Internal error", response.msg
98
97
  ensure
99
98
  Rails.application.env_config["action_dispatch.show_detailed_exceptions"] = true
100
- Rails.application.env_config["action_dispatch.show_exceptions"] = false
101
99
  end
102
100
 
103
101
  test "before error" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_twirp
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.15'
4
+ version: '0.17'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bouke van der Bijl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-13 00:00:00.000000000 Z
11
+ date: 2024-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -19,16 +19,7 @@ dependencies:
19
19
  version: 6.1.3
20
20
  - - "!="
21
21
  - !ruby/object:Gem::Version
22
- version: 7.1.0
23
- - - "!="
24
- - !ruby/object:Gem::Version
25
- version: 7.1.1
26
- - - "!="
27
- - !ruby/object:Gem::Version
28
- version: 7.1.2
29
- - - "!="
30
- - !ruby/object:Gem::Version
31
- version: 7.1.3
22
+ version: '7.1'
32
23
  type: :runtime
33
24
  prerelease: false
34
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,16 +29,7 @@ dependencies:
38
29
  version: 6.1.3
39
30
  - - "!="
40
31
  - !ruby/object:Gem::Version
41
- version: 7.1.0
42
- - - "!="
43
- - !ruby/object:Gem::Version
44
- version: 7.1.1
45
- - - "!="
46
- - !ruby/object:Gem::Version
47
- version: 7.1.2
48
- - - "!="
49
- - !ruby/object:Gem::Version
50
- version: 7.1.3
32
+ version: '7.1'
51
33
  - !ruby/object:Gem::Dependency
52
34
  name: twirp
53
35
  requirement: !ruby/object:Gem::Requirement
@@ -55,9 +37,6 @@ dependencies:
55
37
  - - ">="
56
38
  - !ruby/object:Gem::Version
57
39
  version: '1.9'
58
- - - "<"
59
- - !ruby/object:Gem::Version
60
- version: '1.11'
61
40
  type: :runtime
62
41
  prerelease: false
63
42
  version_requirements: !ruby/object:Gem::Requirement
@@ -65,9 +44,20 @@ dependencies:
65
44
  - - ">="
66
45
  - !ruby/object:Gem::Version
67
46
  version: '1.9'
68
- - - "<"
47
+ - !ruby/object:Gem::Dependency
48
+ name: pry
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
69
59
  - !ruby/object:Gem::Version
70
- version: '1.11'
60
+ version: '0'
71
61
  description:
72
62
  email:
73
63
  - bouke@cheddar.me
@@ -78,7 +68,6 @@ files:
78
68
  - ".github/dependabot.yml"
79
69
  - ".github/workflows/test.yml"
80
70
  - ".gitignore"
81
- - ".ruby-version"
82
71
  - ".standard.yml"
83
72
  - CHANGELOG.md
84
73
  - Gemfile
@@ -191,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
180
  - !ruby/object:Gem::Version
192
181
  version: '0'
193
182
  requirements: []
194
- rubygems_version: 3.5.3
183
+ rubygems_version: 3.5.18
195
184
  signing_key:
196
185
  specification_version: 4
197
186
  summary: Integrate Twirp into Rails
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 3.3.0