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

Cryptic exception when region is not set #325

Closed
darrenhaken opened this issue Sep 21, 2017 · 10 comments
Closed

Cryptic exception when region is not set #325

darrenhaken opened this issue Sep 21, 2017 · 10 comments

Comments

@darrenhaken
Copy link

I was trying to run awspec tests on Jenkins where the AWS region was not set. The error I receive is the following:

Failures:

  1) alb 'app_load_balancer' should be active
     Failure/Error: it { is_expected.to be_active }
     
     NoMethodError:
       undefined method `state' for nil:NilClass
     # ./.bundle/ruby/2.1.0/gems/awspec-0.85.2/lib/awspec/type/alb.rb:17:in `block (2 levels) in <class:Alb>'
     # ./spec/application_load_balancer_spec.rb:4:in `block (2 levels) in <top (required)>'

This caused us to lose a lot of time where if awspec where a readable error would help a lot.

Does this make sense?

@k1LoW
Copy link
Owner

k1LoW commented Nov 10, 2017

@darrenhaken
awspec does not maintain many error messages ( this is RSpec default ).
If you are able to resolve this, we would encourage you to send a pull request.

@IssueHuntBot
Copy link

@issuehuntfest has funded $20.00 to this issue. See it on IssueHunt

@glasswalk3r
Copy link
Contributor

glasswalk3r commented Mar 6, 2019

I believe PR #458 fix this issue.
Maybe the check on directory ~/.aws directory should be also extended to checking environment variables as well, but I'm not sure if this is desirable or not.
@k1LoW, look like AWS ALB also raises exceptions when a non-existing LB is searched, which puts it in the same situation as described at issue #445: we need to add exceptions to the stub to properly test that.
Now the evidence. Please consider the spec below:

require 'spec_helper'

describe alb('foobar') do
  it { should_not exist }
  it 'active? method raises Awspec::NoExistingResource' do
    expect { subject.active? }.to raise_error(Awspec::NoExistingResource)
  end
end

If you run it with region properly configured in ~/.aws/config file:

$ bundle exec rspec spec/type/alb_spec2.rb
..

Finished in 0.02881 seconds (files took 4.07 seconds to load)
2 examples, 0 failures

If the region configuration is removed:

$ bundle exec rspec spec/type/alb_spec2.rb

An error occurred while loading ./spec/type/alb_spec2.rb.
Failure/Error: raise "Ops... there is something wrong with AWS client configuration => #{e}"

RuntimeError:
  Ops... there is something wrong with AWS client configuration => missing region; use :region option or export region name to ENV['AWS_REGION']
# ./lib/awspec/helper/finder.rb:156:in `rescue in <module:Finder>'
# ./lib/awspec/helper/finder.rb:153:in `<module:Finder>'
# ./lib/awspec/helper/finder.rb:54:in `<module:Helper>'
# ./lib/awspec/helper/finder.rb:53:in `<top (required)>'
# ./lib/awspec/type/base.rb:3:in `require'
# ./lib/awspec/type/base.rb:3:in `<top (required)>'
# ./lib/awspec/helper/type.rb:4:in `require'
# ./lib/awspec/helper/type.rb:4:in `<module:Type>'
# ./lib/awspec/helper/type.rb:3:in `<module:Helper>'
# ./lib/awspec/helper/type.rb:2:in `<module:Awspec>'
# ./lib/awspec/helper/type.rb:1:in `<top (required)>'
# ./lib/awspec/helper.rb:2:in `require'
# ./lib/awspec/helper.rb:2:in `<top (required)>'
# ./lib/awspec.rb:15:in `require'
# ./lib/awspec.rb:15:in `<top (required)>'
# ./spec/spec_helper.rb:1:in `require'
# ./spec/spec_helper.rb:1:in `<top (required)>'
# ./spec/type/alb_spec2.rb:1:in `require'
# ./spec/type/alb_spec2.rb:1:in `<top (required)>'
# ------------------
# --- Caused by: ---
# Aws::Errors::MissingRegionError:
#   missing region; use :region option or export region name to ENV['AWS_REGION']
#   ./lib/awspec/helper/finder.rb:154:in `<module:Finder>'
No examples found.


Finished in 0.00043 seconds (files took 4.09 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

@majormoses
Copy link

It makes sense but I we should consider that the region can come from multiple locations such as an ENV var not just a config file. Ideally it would be good to support passing the region to the assertion itself but I took a quick look and did not see that currently supported here.

@glasswalk3r
Copy link
Contributor

I updated the configuration @majormoses to ignore how the configuration is done (files or environment variable), and just testing if the client configuration is correct or not, see PR #458.

@glasswalk3r
Copy link
Contributor

@k1LoW , the PR #458 is waiting for a long time to be approved and it should be good to go.

@k1LoW
Copy link
Owner

k1LoW commented Jun 28, 2021

@glasswalk3r hai! Thank you!

@glasswalk3r
Copy link
Contributor

I created a new PR for this case, hopefully I got it right this time.

@glasswalk3r
Copy link
Contributor

@k1LoW , the PR is already merged, you can close this one!

@k1LoW
Copy link
Owner

k1LoW commented Aug 1, 2021

👍

@k1LoW k1LoW closed this as completed Aug 1, 2021
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

5 participants