Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ Changelog for the gruf gem. This includes internal history before the gem was ma

### Pending release

* [#184] [Breaking] Controller unhandled errors should be passed as BadStatus to interceptors.
* Server interceptors should now expect a `GRPC::BadStatus` error in the case of unhandled errors.
Orignal unhandled error can be reached via `cause`. example:
```ruby
def call
begin
yield
rescue => err
err.cause
end
end
```

### 2.21.0

* [#221] Add support for Ruby 3.4
Expand Down
12 changes: 6 additions & 6 deletions lib/gruf/controllers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ def process_action(method_key, &block)
def call(method_key, &block)
Interceptors::Context.new(@interceptors).intercept! do
process_action(method_key, &block)
rescue GRPC::BadStatus
raise # passthrough, to be caught by Gruf::Interceptors::Timer
rescue GRPC::Core::CallError, StandardError => e # CallError is not a StandardError
set_debug_info(e.message, e.backtrace) if Gruf.backtrace_on_error
error_message = Gruf.use_exception_message ? e.message : Gruf.internal_error_message
fail!(:internal, :unknown, error_message)
end
rescue GRPC::BadStatus
raise # passthrough, to be caught by Gruf::Interceptors::Timer
rescue GRPC::Core::CallError, StandardError => e # CallError is not a StandardError
set_debug_info(e.message, e.backtrace) if Gruf.backtrace_on_error
error_message = Gruf.use_exception_message ? e.message : Gruf.internal_error_message
fail!(:internal, :unknown, error_message)
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/gruf/controllers/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@
end
end

it 'raises a GRPC::Internal error to interceptors' do
Gruf.interceptors.use(TestServerInterceptor)
expect_any_instance_of(TestServerInterceptor).to receive(:call) do |&block|
error = nil
expect { block.call }.to raise_error(GRPC::Internal) { |err| error = err }
raise error if error
end
expect { subject }.to raise_error(GRPC::Internal)
end

context 'when backtrace_on_error is set to true' do
before do
Gruf.backtrace_on_error = true
Expand Down