Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cluster: Preserve message and suberrors when raising CommandErrorCollection #1238

Merged
Merged
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
9 changes: 8 additions & 1 deletion cluster/lib/redis/cluster/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ def handle_errors
raise ERROR_MAPPING.fetch(node_error.class), node_error.message, node_error.backtrace
end
end
raise ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
remapped_node_errors = error.errors.map do |node_key, node_error|
remapped = ERROR_MAPPING.fetch(node_error.class, node_error.class).new(node_error.message)
remapped.set_backtrace node_error.backtrace
[node_key, remapped]
end.to_h
raise(Redis::Cluster::CommandErrorCollection.new(remapped_node_errors, error.message).tap do |remapped|
remapped.set_backtrace error.backtrace
end)
rescue ::RedisClient::Error => error
raise ERROR_MAPPING.fetch(error.class), error.message, error.backtrace
end
Expand Down
4 changes: 3 additions & 1 deletion cluster/test/commands_on_server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ def test_bgsave
'Use BGSAVE SCHEDULE in order to schedule a BGSAVE whenever possible.'

redis_cluster_mock(bgsave: ->(*_) { "-Error #{err_msg}" }) do |redis|
assert_raises(Redis::Cluster::CommandErrorCollection, 'Command error replied on any node') do
err = assert_raises(Redis::Cluster::CommandErrorCollection, 'Command error replied on any node') do
redis.bgsave
end
assert_includes err.message, err_msg
assert_kind_of Redis::CommandError, err.errors.values.first
end
end

Expand Down
Loading