rails_twirp 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile +9 -0
- data/lib/rails_twirp/base.rb +2 -0
- data/lib/rails_twirp/exception_handling.rb +26 -0
- data/lib/rails_twirp/route_set.rb +2 -0
- data/lib/rails_twirp/version.rb +1 -1
- data/test/ping_controller_test.rb +27 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e2d7bf09840bf1a4d5aef432df4a47d50e653fe618781324d535c382b222cd9
|
4
|
+
data.tar.gz: 7481248258f806ea042f16bd12e09822be2f3d0abcd80c864ab0328572f428ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed132bcafa1a4801ad6196bb26c76e11dbee3ec64a672363eaf46583189fdc58a6fcc515d5bc4525c5125f6ce06b11a00ac914dbfcc4252c93abedc89a58f4f1
|
7
|
+
data.tar.gz: 2469cfc961274f0cac6938951723e425f182becba4b95349c70c981e93f197551068b5124cf3afe687d1f537a3355787b3621275506650c02f5ac1c1c914530e
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.3
|
data/Gemfile
CHANGED
@@ -7,3 +7,12 @@ gem "sqlite3"
|
|
7
7
|
gem "pbbuilder", "~> 0.10.0"
|
8
8
|
gem "standard"
|
9
9
|
gem "pry"
|
10
|
+
|
11
|
+
# HACK(bouk): Overwrite Bundler's platform matcher to ignore universal CPU
|
12
|
+
# The protobuf and gRPC 'universal' macOS gems break on M1
|
13
|
+
module Bundler::MatchPlatform
|
14
|
+
def match_platform(p)
|
15
|
+
return false if ::Gem::Platform === platform && platform.cpu == "universal"
|
16
|
+
Bundler::MatchPlatform.platforms_match?(platform, p)
|
17
|
+
end
|
18
|
+
end
|
data/lib/rails_twirp/base.rb
CHANGED
@@ -12,6 +12,7 @@ require "rails_twirp/rescue"
|
|
12
12
|
require "rails_twirp/url_for"
|
13
13
|
require "rails_twirp/implicit_render"
|
14
14
|
require "rails_twirp/instrumentation"
|
15
|
+
require "rails_twirp/exception_handling"
|
15
16
|
|
16
17
|
module RailsTwirp
|
17
18
|
class Base < AbstractController::Base
|
@@ -36,6 +37,7 @@ module RailsTwirp
|
|
36
37
|
include AbstractController::Callbacks
|
37
38
|
include Rescue
|
38
39
|
include Instrumentation
|
40
|
+
include ExceptionHandling
|
39
41
|
|
40
42
|
attr_internal :request, :env, :response_class, :rpc_name
|
41
43
|
def initialize
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "twirp/error"
|
2
|
+
|
3
|
+
module RailsTwirp
|
4
|
+
module ExceptionHandling
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
include AbstractController::Logger
|
8
|
+
|
9
|
+
def process_action(*)
|
10
|
+
super
|
11
|
+
rescue Exception => e
|
12
|
+
# We adopt the same error handling logic as Rails' standard middlewares:
|
13
|
+
# 1. When we 'show exceptions' we make the exception bubble up—this is useful for testing
|
14
|
+
raise e unless http_request.show_exceptions?
|
15
|
+
|
16
|
+
# 2. When we want to show detailed exceptions we include the exception message in the error
|
17
|
+
if http_request.get_header("action_dispatch.show_detailed_exceptions")
|
18
|
+
self.response_body = Twirp::Error.internal_with(e)
|
19
|
+
return
|
20
|
+
end
|
21
|
+
|
22
|
+
# 3. Otherwise we just return a vague internal error message
|
23
|
+
self.response_body = Twirp::Error.internal("Internal error")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/rails_twirp/version.rb
CHANGED
@@ -46,12 +46,38 @@ class PingControllerTest < RailsTwirp::IntegrationTest
|
|
46
46
|
assert_equal :not_found, response.code
|
47
47
|
end
|
48
48
|
|
49
|
-
test "uncaught
|
49
|
+
test "uncaught errors should bubble up to the test" do
|
50
|
+
req = RPC::DummyAPI::PingRequest.new
|
51
|
+
assert_raises StandardError, "Uncaught" do
|
52
|
+
rpc RPC::DummyAPI::DummyService, "UncaughtError", req
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
test "uncaught errors should return an internal error with details if show_exceptions is true" do
|
57
|
+
Rails.application.env_config["action_dispatch.show_exceptions"] = true
|
58
|
+
|
50
59
|
req = RPC::DummyAPI::PingRequest.new
|
51
60
|
rpc RPC::DummyAPI::DummyService, "UncaughtError", req
|
52
61
|
assert_instance_of Twirp::Error, response
|
62
|
+
assert_equal :internal, response.code
|
53
63
|
assert_equal "Uncaught", response.msg
|
64
|
+
assert_equal "StandardError", response.meta["cause"]
|
65
|
+
ensure
|
66
|
+
Rails.application.env_config["action_dispatch.show_exceptions"] = false
|
67
|
+
end
|
68
|
+
|
69
|
+
test "uncaught errors should return an internal error without if show_exceptions is true and show_detailed_exceptions is false" do
|
70
|
+
Rails.application.env_config["action_dispatch.show_exceptions"] = true
|
71
|
+
Rails.application.env_config["action_dispatch.show_detailed_exceptions"] = false
|
72
|
+
|
73
|
+
req = RPC::DummyAPI::PingRequest.new
|
74
|
+
rpc RPC::DummyAPI::DummyService, "UncaughtError", req
|
75
|
+
assert_instance_of Twirp::Error, response
|
54
76
|
assert_equal :internal, response.code
|
77
|
+
assert_equal "Internal error", response.msg
|
78
|
+
ensure
|
79
|
+
Rails.application.env_config["action_dispatch.show_detailed_exceptions"] = true
|
80
|
+
Rails.application.env_config["action_dispatch.show_exceptions"] = false
|
55
81
|
end
|
56
82
|
|
57
83
|
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.
|
4
|
+
version: 0.10.0
|
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: 2021-12-
|
11
|
+
date: 2021-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -47,6 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- ".github/workflows/test.yml"
|
49
49
|
- ".gitignore"
|
50
|
+
- ".ruby-version"
|
50
51
|
- ".standard.yml"
|
51
52
|
- Gemfile
|
52
53
|
- MIT-LICENSE
|
@@ -59,6 +60,7 @@ files:
|
|
59
60
|
- lib/rails_twirp/base.rb
|
60
61
|
- lib/rails_twirp/engine.rb
|
61
62
|
- lib/rails_twirp/errors.rb
|
63
|
+
- lib/rails_twirp/exception_handling.rb
|
62
64
|
- lib/rails_twirp/implicit_render.rb
|
63
65
|
- lib/rails_twirp/instrumentation.rb
|
64
66
|
- lib/rails_twirp/log_subscriber.rb
|
@@ -157,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
159
|
- !ruby/object:Gem::Version
|
158
160
|
version: '0'
|
159
161
|
requirements: []
|
160
|
-
rubygems_version: 3.2.
|
162
|
+
rubygems_version: 3.2.32
|
161
163
|
signing_key:
|
162
164
|
specification_version: 4
|
163
165
|
summary: Integrate Twirp into Rails
|