Skip to content

Commit

Permalink
Merge pull request #147 from Metallion/display-error-msgs
Browse files Browse the repository at this point in the history
Include the error messages when we fail due to too many errors.
  • Loading branch information
leandromoreira committed Oct 30, 2023
2 parents d31702e + f621fef commit fbe2b28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/redlock/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ def lock_instances(resource, ttl, options)
@servers.each { |s| s.unlock(resource, value) }

if errors.size >= @quorum
raise LockAcquisitionError.new('Too many Redis errors prevented lock acquisition', errors)
err_msgs = errors.map { |e| "#{e.class}: #{e.message}" }.join("\n")
raise LockAcquisitionError.new("Too many Redis errors prevented lock acquisition:\n#{err_msgs}", errors)
end

false
Expand Down
12 changes: 11 additions & 1 deletion spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,19 @@
it 'fails to acquire a lock if majority of Redis instances are not available' do
redlock = Redlock::Client.new(servers_without_quorum)

expected_msg = <<~MSG
failed to acquire lock on 'Too many Redis errors prevented lock acquisition:
RedisClient::CannotConnectError: Connection refused - connect(2) for 127.0.0.1:46864
RedisClient::CannotConnectError: Connection refused - connect(2) for 127.0.0.1:46864'
MSG

expect {
redlock.lock(resource_key, ttl)
}.to raise_error(Redlock::LockAcquisitionError)
}.to raise_error do |error|
expect(error).to be_a(Redlock::LockAcquisitionError)
expect(error.message).to eq(expected_msg.chomp)
expect(error.errors.size).to eq(2)
end
end
end

Expand Down

0 comments on commit fbe2b28

Please sign in to comment.