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

Vault.with_retries does not return exception #68

Closed
assimovt opened this issue Mar 30, 2016 · 7 comments
Closed

Vault.with_retries does not return exception #68

assimovt opened this issue Mar 30, 2016 · 7 comments

Comments

@assimovt
Copy link

Not sure whether it's a bug, but I can't get the Vault.with_retries to return the exception:

require 'vault'

Vault.with_retries(Vault::HTTPConnectionError, Vault::HTTPError) do |attempt, e|
  puts "Received exception #{e.inspect} from Vault - attempt #{attempt}"
  Vault.logical.read("secret/bacon")
end

Output:

Received exception nil from Vault - attempt 0
Received exception nil from Vault - attempt 1
Received exception nil from Vault - attempt 2

Ruby version: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]

Thoughts? Thanks!

@sethvargo
Copy link
Contributor

Hi @assimovt

In your example, no exception is being raise ("exception nil"). That means Vault.logical.read is returning a value, albeit nil.

@assimovt
Copy link
Author

@sethvargo I actually have the vault stopped, so there is Exception raised that it can't connect. Here is the full output:

Received exception nil from Vault - attempt 0
Received exception nil from Vault - attempt 1
Received exception nil from Vault - attempt 2
Vault::HTTPClientError: The Vault server at `http://127.0.0.1:8200' responded with a 403.
Any additional information the server supplied is shown below:

  * permission denied

Please refer to the documentation for help.

@sethvargo
Copy link
Contributor

Hi @assimovt

Can you please share the complete script you're running? It looks like the error is printed out there at the end?

@assimovt
Copy link
Author

@sethvargo I don't have any script :) I just paste those lines into IRB session:

➜  ~ irb
irb(main):001:0> require 'vault'
=> true
irb(main):002:0>
irb(main):003:0* Vault.with_retries(Vault::HTTPConnectionError, Vault::HTTPError) do |attempt, e|
irb(main):004:1*   puts "Received exception #{e.inspect} from Vault - attempt #{attempt}"
irb(main):005:1>   Vault.logical.read("secret/bacon")
irb(main):006:1> end
Received exception nil from Vault - attempt 0
Received exception nil from Vault - attempt 1
Received exception nil from Vault - attempt 2
Vault::HTTPConnectionError: The Vault server at `https://127.0.0.1:8200' is not currently
accepting connections. Please ensure that the server is running and that your
authentication information is correct.

The original error was `Errno::ECONNREFUSED'. Additional information (if any) is
shown below:

    Failed to open TCP connection to 127.0.0.1:8200 (Connection refused - connect(2) for "127.0.0.1" port 8200)

Please refer to the documentation for more help.

    from /Users/tair/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/vault-0.3.0/lib/vault/client.rb:228:in `rescue in request'
    from /Users/tair/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/vault-0.3.0/lib/vault/client.rb:212:in `request'
    from /Users/tair/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/vault-0.3.0/lib/vault/client.rb:78:in `get'
    from /Users/tair/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/vault-0.3.0/lib/vault/api/logical.rb:45:in `read'
    from (irb):5:in `block in irb_binding'
    from /Users/tair/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/vault-0.3.0/lib/vault/client.rb:356:in `with_retries'
    from /Users/tair/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/vault-0.3.0/lib/vault.rb:35:in `method_missing'
    from (irb):3
    from /Users/tair/.rbenv/versions/2.3.0/bin/irb:11:in `<main>'

@sethvargo
Copy link
Contributor

Hi @assimovt

That seems to be behaving as expected to me? I'm confused what behavior you're expecting? The default retries are exhausted, so the exception is raised when the third attempt fails.

@assimovt
Copy link
Author

I was expecting the exception to be printed out, as shown in the example in Readme.md:

Vault.with_retries(Vault::HTTPConnectionError, Vault::HTTPError) do |attempt, e|
  log "Received exception #{e} from Vault - attempt #{attempt}"
  Vault.logical.read("secret/bacon")
end

For me, it's always nil, so I can't report it further to my 3rd party service. What do you get from the example above?

I see that it's only yielding here attempts, but not the actual exception? Or am I totally missing something here? 👓 😅

@assimovt
Copy link
Author

Thanks @sethvargo 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants