From b7b8367770f9443ae0ff59a8ce6ff8e982bc146f Mon Sep 17 00:00:00 2001 From: James Bence Date: Mon, 1 Jul 2013 16:47:29 -0700 Subject: [PATCH 1/6] Inspect error.response.body, not error.message Recent versions of excon have a middleware component, Excon::Middleware::Expects and fog requests mostly record an expectation of a 200 status code. Some calls to AWS return status other than 200 and in some cases the error handling obscures the underlying error. Current handling parsed error.message; this instance of error is constructed by excon and includes the response as an attribute. The message is always something like 'Expected(200) <=> Actual(404 Not Found)' and so the parsing never succeeds. Instead we now attempt to parse error.response.body which should allow extraction of the underlying AWS Code value, which in turn will produce an exception that points to the actual underlying cause. --- lib/fog/aws/auto_scaling.rb | 2 +- lib/fog/aws/beanstalk.rb | 2 +- lib/fog/aws/cloud_formation.rb | 2 +- lib/fog/aws/compute.rb | 2 +- lib/fog/aws/elasticache.rb | 2 +- lib/fog/aws/elb.rb | 2 +- lib/fog/aws/iam.rb | 2 +- lib/fog/aws/rds.rb | 4 ++++ lib/fog/aws/sts.rb | 2 +- 9 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/fog/aws/auto_scaling.rb b/lib/fog/aws/auto_scaling.rb index 4fcd6b2b1..cf43b8a52 100644 --- a/lib/fog/aws/auto_scaling.rb +++ b/lib/fog/aws/auto_scaling.rb @@ -153,7 +153,7 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.message.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) + if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) case match[1] when 'AlreadyExists' #raise Fog::AWS::AutoScaling::IdentifierTaken.new(match[2]) diff --git a/lib/fog/aws/beanstalk.rb b/lib/fog/aws/beanstalk.rb index 66a0f7d39..9ff317d3e 100644 --- a/lib/fog/aws/beanstalk.rb +++ b/lib/fog/aws/beanstalk.rb @@ -131,7 +131,7 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.message.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) + if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) raise case match[1].split('.').last when 'InvalidParameterValue' Fog::AWS::ElasticBeanstalk::InvalidParameterError.slurp(error, match[2]) diff --git a/lib/fog/aws/cloud_formation.rb b/lib/fog/aws/cloud_formation.rb index 1e6b9a541..d8880536c 100644 --- a/lib/fog/aws/cloud_formation.rb +++ b/lib/fog/aws/cloud_formation.rb @@ -108,7 +108,7 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.message.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) + if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) raise case match[1].split('.').last when 'NotFound', 'ValidationError' Fog::AWS::CloudFormation::NotFound.slurp(error, match[2]) diff --git a/lib/fog/aws/compute.rb b/lib/fog/aws/compute.rb index 052632dac..16591377f 100644 --- a/lib/fog/aws/compute.rb +++ b/lib/fog/aws/compute.rb @@ -392,7 +392,7 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.message.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) + if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) raise case match[1].split('.').last when 'NotFound', 'Unknown' Fog::Compute::AWS::NotFound.slurp(error, match[2]) diff --git a/lib/fog/aws/elasticache.rb b/lib/fog/aws/elasticache.rb index 946fc7de3..063a0929b 100644 --- a/lib/fog/aws/elasticache.rb +++ b/lib/fog/aws/elasticache.rb @@ -104,7 +104,7 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.message.match(/(?:.*(.*)<\/Code>?)/m) + if match = error.response.body.match(/(?:.*(.*)<\/Code>?)/m) case match[1] when 'CacheSecurityGroupNotFound', 'CacheParameterGroupNotFound', 'CacheClusterNotFound' diff --git a/lib/fog/aws/elb.rb b/lib/fog/aws/elb.rb index 9e529dc1e..068470b6f 100644 --- a/lib/fog/aws/elb.rb +++ b/lib/fog/aws/elb.rb @@ -191,7 +191,7 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.message.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) + if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) case match[1] when 'CertificateNotFound' raise Fog::AWS::IAM::NotFound.slurp(error, match[2]) diff --git a/lib/fog/aws/iam.rb b/lib/fog/aws/iam.rb index aab437ecf..94cd12571 100644 --- a/lib/fog/aws/iam.rb +++ b/lib/fog/aws/iam.rb @@ -208,7 +208,7 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.message.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) + if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) case match[1] when 'CertificateNotFound', 'NoSuchEntity' raise Fog::AWS::IAM::NotFound.slurp(error, match[2]) diff --git a/lib/fog/aws/rds.rb b/lib/fog/aws/rds.rb index 2d6884cc8..7f57d576b 100644 --- a/lib/fog/aws/rds.rb +++ b/lib/fog/aws/rds.rb @@ -218,6 +218,10 @@ module Fog raise end else + case error.message + when 'Not Found' + raise Fog::AWS::RDS::NotFound.slurp(error, 'RDS Instance not found') + end raise end end diff --git a/lib/fog/aws/sts.rb b/lib/fog/aws/sts.rb index 22248b1c0..a3dbbf9b1 100644 --- a/lib/fog/aws/sts.rb +++ b/lib/fog/aws/sts.rb @@ -114,7 +114,7 @@ module Fog response rescue Excon::Errors::HTTPStatusError => error - if match = error.message.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) + if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) case match[1] when 'EntityAlreadyExists', 'KeyPairMismatch', 'LimitExceeded', 'MalformedCertificate', 'ValidationError' raise Fog::AWS::STS.const_get(match[1]).slurp(error, match[2]) From 7fb0e3753e0e6c556e9ee15c578d6ad4c144658a Mon Sep 17 00:00:00 2001 From: James Bence Date: Tue, 2 Jul 2013 19:39:23 -0700 Subject: [PATCH 2/6] Refactor error handling Match against the error object in both the old (against error.message) and the new (against error.response.body); return a hash from this method. In the rescue block, try hard to raise an exception that includes the code and message extracted from the error. --- lib/fog/aws.rb | 11 +++++++ lib/fog/aws/auto_scaling.rb | 31 ++++++++---------- lib/fog/aws/beanstalk.rb | 18 +++++----- lib/fog/aws/cloud_formation.rb | 21 +++++------- lib/fog/aws/compute.rb | 18 +++++----- lib/fog/aws/elasticache.rb | 30 ++++++++--------- lib/fog/aws/elb.rb | 60 ++++++++++++++++------------------ lib/fog/aws/iam.rb | 23 ++++++------- lib/fog/aws/rds.rb | 41 +++++++++++++---------- lib/fog/aws/sts.rb | 24 +++++--------- 10 files changed, 134 insertions(+), 143 deletions(-) diff --git a/lib/fog/aws.rb b/lib/fog/aws.rb index 9f0ba2a30..dbc59f9a3 100644 --- a/lib/fog/aws.rb +++ b/lib/fog/aws.rb @@ -301,5 +301,16 @@ module Fog end options end + + module Errors + def self.match_error(error) + matcher = lambda {|s| s.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m)} + [error.message, error.response.body].each(&Proc.new {|s| + match = matcher.call(s) + return {code: match[1].split('.').last, message: match[2]} if match + }) + {} # we did not match the message or response body + end + end end end diff --git a/lib/fog/aws/auto_scaling.rb b/lib/fog/aws/auto_scaling.rb index cf43b8a52..63d189ff4 100644 --- a/lib/fog/aws/auto_scaling.rb +++ b/lib/fog/aws/auto_scaling.rb @@ -143,7 +143,7 @@ module Fog def _request(body, idempotent, parser) begin - response = @connection.request({ + @connection.request({ :body => body, :expects => 200, :idempotent => idempotent, @@ -153,24 +153,19 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) - case match[1] - when 'AlreadyExists' - #raise Fog::AWS::AutoScaling::IdentifierTaken.new(match[2]) - raise Fog::AWS::AutoScaling::IdentifierTaken.slurp(error, match[2]) - when 'ResourceInUse' - raise Fog::AWS::AutoScaling::ResourceInUse.slurp(error, match[2]) - when 'ValidationError' - raise Fog::AWS::AutoScaling::ValidationError.slurp(error, match[2]) - else - raise Fog::Compute::AWS::Error.slurp(error, "#{match[1]} => #{match[2]}") - end - else - raise - end + match = Fog::AWS::Errors.match_error(error) + raise if match.empty? + raise case match[:code] + when 'AlreadyExists' + Fog::AWS::AutoScaling::IdentifierTaken.slurp(error, match[:message]) + when 'ResourceInUse' + Fog::AWS::AutoScaling::ResourceInUse.slurp(error, match[:message]) + when 'ValidationError' + Fog::AWS::AutoScaling::ValidationError.slurp(error, match[:message]) + else + Fog::Compute::AWS::Error.slurp(error, "#{match[:code]} => #{match[:message]}") + end end - - response end def setup_credentials(options) diff --git a/lib/fog/aws/beanstalk.rb b/lib/fog/aws/beanstalk.rb index 9ff317d3e..1250d72ff 100644 --- a/lib/fog/aws/beanstalk.rb +++ b/lib/fog/aws/beanstalk.rb @@ -131,16 +131,14 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) - raise case match[1].split('.').last - when 'InvalidParameterValue' - Fog::AWS::ElasticBeanstalk::InvalidParameterError.slurp(error, match[2]) - else - Fog::AWS::ElasticBeanstalk::Error.slurp(error, "#{match[1]} => #{match[2]}") - end - else - raise error - end + match = Fog::AWS::Errors.match_error(error) + raise if match.empty? + raise case match[:code] + when 'InvalidParameterValue' + Fog::AWS::ElasticBeanstalk::InvalidParameterError.slurp(error, match[:message]) + else + Fog::AWS::ElasticBeanstalk::Error.slurp(error, "#{match[:code]} => #{match[:message]}") + end end end diff --git a/lib/fog/aws/cloud_formation.rb b/lib/fog/aws/cloud_formation.rb index d8880536c..db46ba2fb 100644 --- a/lib/fog/aws/cloud_formation.rb +++ b/lib/fog/aws/cloud_formation.rb @@ -98,7 +98,7 @@ module Fog ) begin - response = @connection.request({ + @connection.request({ :body => body, :expects => 200, :idempotent => idempotent, @@ -108,19 +108,16 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) - raise case match[1].split('.').last - when 'NotFound', 'ValidationError' - Fog::AWS::CloudFormation::NotFound.slurp(error, match[2]) - else - Fog::AWS::CloudFormation::Error.slurp(error, "#{match[1]} => #{match[2]}") - end - else - raise error - end + match = Fog::AWS::Errors.match_error(error) + raise if match.empty? + raise case match[:code] + when 'NotFound', 'ValidationError' + Fog::AWS::CloudFormation::NotFound.slurp(error, match[:message]) + else + Fog::AWS::CloudFormation::Error.slurp(error, "#{match[:code]} => #{match[:message]}") + end end - response end end diff --git a/lib/fog/aws/compute.rb b/lib/fog/aws/compute.rb index 16591377f..3551d0a02 100644 --- a/lib/fog/aws/compute.rb +++ b/lib/fog/aws/compute.rb @@ -392,16 +392,14 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) - raise case match[1].split('.').last - when 'NotFound', 'Unknown' - Fog::Compute::AWS::NotFound.slurp(error, match[2]) - else - Fog::Compute::AWS::Error.slurp(error, "#{match[1]} => #{match[2]}") - end - else - raise error - end + match = Fog::AWS::Errors.match_error(error) + raise if match.empty? + raise case match[:code] + when 'NotFound', 'Unknown' + Fog::Compute::AWS::NotFound.slurp(error, match[:message]) + else + Fog::Compute::AWS::Error.slurp(error, "#{match[:code]} => #{match[:message]}") + end end end diff --git a/lib/fog/aws/elasticache.rb b/lib/fog/aws/elasticache.rb index 063a0929b..2db7e5f2c 100644 --- a/lib/fog/aws/elasticache.rb +++ b/lib/fog/aws/elasticache.rb @@ -94,7 +94,7 @@ module Fog ) begin - response = @connection.request({ + @connection.request({ :body => body, :expects => 200, :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, @@ -104,24 +104,20 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.response.body.match(/(?:.*(.*)<\/Code>?)/m) - case match[1] - when 'CacheSecurityGroupNotFound', 'CacheParameterGroupNotFound', - 'CacheClusterNotFound' - raise Fog::AWS::Elasticache::NotFound - when 'CacheSecurityGroupAlreadyExists' - raise Fog::AWS::Elasticache::IdentifierTaken - when 'InvalidParameterValue' - raise Fog::AWS::Elasticache::InvalidInstance - else - raise - end - else - raise - end + match = Fog::AWS::Errors.match_error(error) + raise if match.empty? + raise case match[:code] + when 'CacheSecurityGroupNotFound', 'CacheParameterGroupNotFound', 'CacheClusterNotFound' + Fog::AWS::Elasticache::NotFound.slurp(error, match[:message]) + when 'CacheSecurityGroupAlreadyExists' + Fog::AWS::Elasticache::IdentifierTaken.slurp(error, match[:message]) + when 'InvalidParameterValue' + Fog::AWS::Elasticache::InvalidInstance.slurp(error, match[:message]) + else + Fog::AWS::Compute::Error.slurp(error, "#{match[:code]} => #{match[:message]}") + end end - response end end diff --git a/lib/fog/aws/elb.rb b/lib/fog/aws/elb.rb index 068470b6f..4f29cf70f 100644 --- a/lib/fog/aws/elb.rb +++ b/lib/fog/aws/elb.rb @@ -191,37 +191,35 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) - case match[1] - when 'CertificateNotFound' - raise Fog::AWS::IAM::NotFound.slurp(error, match[2]) - when 'DuplicateLoadBalancerName' - raise Fog::AWS::ELB::IdentifierTaken.slurp(error, match[2]) - when 'DuplicatePolicyName' - raise Fog::AWS::ELB::DuplicatePolicyName.slurp(error, match[2]) - when 'InvalidInstance' - raise Fog::AWS::ELB::InvalidInstance.slurp(error, match[2]) - when 'InvalidConfigurationRequest' - # when do they fucking use this shit? - raise Fog::AWS::ELB::InvalidConfigurationRequest.slurp(error, match[2]) - when 'LoadBalancerNotFound' - raise Fog::AWS::ELB::NotFound.slurp(error, match[2]) - when 'PolicyNotFound' - raise Fog::AWS::ELB::PolicyNotFound.slurp(error, match[2]) - when 'PolicyTypeNotFound' - raise Fog::AWS::ELB::PolicyTypeNotFound.slurp(error, match[2]) - when 'Throttling' - raise Fog::AWS::ELB::Throttled.slurp(error, match[2]) - when 'TooManyPolicies' - raise Fog::AWS::ELB::TooManyPolicies.slurp(error, match[2]) - when 'ValidationError' - raise Fog::AWS::ELB::ValidationError.slurp(error, match[2]) - else - raise - end - else - raise - end + match = Fog::AWS::Errors.match_error(error) + raise if match.empty? + raise case match[:code] + when 'CertificateNotFound' + Fog::AWS::IAM::NotFound.slurp(error, match[:message]) + when 'DuplicateLoadBalancerName' + Fog::AWS::ELB::IdentifierTaken.slurp(error, match[:message]) + when 'DuplicatePolicyName' + Fog::AWS::ELB::DuplicatePolicyName.slurp(error, match[:message]) + when 'InvalidInstance' + Fog::AWS::ELB::InvalidInstance.slurp(error, match[:message]) + when 'InvalidConfigurationRequest' + # when do they fucking use this shit? + Fog::AWS::ELB::InvalidConfigurationRequest.slurp(error, match[:message]) + when 'LoadBalancerNotFound' + Fog::AWS::ELB::NotFound.slurp(error, match[:message]) + when 'PolicyNotFound' + Fog::AWS::ELB::PolicyNotFound.slurp(error, match[:message]) + when 'PolicyTypeNotFound' + Fog::AWS::ELB::PolicyTypeNotFound.slurp(error, match[:message]) + when 'Throttling' + Fog::AWS::ELB::Throttled.slurp(error, match[:message]) + when 'TooManyPolicies' + Fog::AWS::ELB::TooManyPolicies.slurp(error, match[:message]) + when 'ValidationError' + Fog::AWS::ELB::ValidationError.slurp(error, match[:message]) + else + Fog::Compute::AWS::Error.slurp(error, "#{match[:code]} => #{match[:message]}") + end end end end diff --git a/lib/fog/aws/iam.rb b/lib/fog/aws/iam.rb index 94cd12571..303af8317 100644 --- a/lib/fog/aws/iam.rb +++ b/lib/fog/aws/iam.rb @@ -208,19 +208,16 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) - case match[1] - when 'CertificateNotFound', 'NoSuchEntity' - raise Fog::AWS::IAM::NotFound.slurp(error, match[2]) - when 'EntityAlreadyExists', 'KeyPairMismatch', 'LimitExceeded', 'MalformedCertificate', 'ValidationError' - raise Fog::AWS::IAM.const_get(match[1]).slurp(error, match[2]) - else - raise Fog::AWS::IAM::Error.slurp(error, "#{match[1]} => #{match[2]}") if match[1] - raise - end - else - raise - end + match = Fog::AWS::Errors.match_error(error) + raise if match.empty? + raise case match[:code] + when 'CertificateNotFound', 'NoSuchEntity' + Fog::AWS::IAM::NotFound.slurp(error, match[:message]) + when 'EntityAlreadyExists', 'KeyPairMismatch', 'LimitExceeded', 'MalformedCertificate', 'ValidationError' + Fog::AWS::IAM.const_get(match[:code]).slurp(error, match[:message]) + else + Fog::AWS::IAM::Error.slurp(error, "#{match[:code]} => #{match[:message]}") + end end end diff --git a/lib/fog/aws/rds.rb b/lib/fog/aws/rds.rb index 7f57d576b..8d605d1ec 100644 --- a/lib/fog/aws/rds.rb +++ b/lib/fog/aws/rds.rb @@ -51,11 +51,15 @@ module Fog request :describe_db_subnet_groups # TODO: :delete_db_subnet_group, :modify_db_subnet_group + request :describe_db_log_files + model_path 'fog/aws/models/rds' model :server collection :servers + model :snapshot collection :snapshots + model :parameter_group collection :parameter_groups @@ -68,6 +72,9 @@ module Fog model :subnet_group collection :subnet_groups + model :log_file + collection :log_files + class Mock def self.data @@ -191,12 +198,12 @@ module Fog :host => @host, :path => @path, :port => @port, - :version => '2012-09-17' #'2011-04-01' + :version => '2013-05-15' #'2012-09-17' #'2011-04-01' } ) begin - response = @connection.request({ + @connection.request({ :body => body, :expects => 200, :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, @@ -206,27 +213,27 @@ module Fog :parser => parser }) rescue Excon::Errors::HTTPStatusError => error - if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) - case match[1].split('.').last - when 'DBInstanceNotFound', 'DBParameterGroupNotFound', 'DBSnapshotNotFound', 'DBSecurityGroupNotFound' - raise Fog::AWS::RDS::NotFound.slurp(error, match[2]) - when 'DBParameterGroupAlreadyExists' - raise Fog::AWS::RDS::IdentifierTaken.slurp(error, match[2]) - when 'AuthorizationAlreadyExists' - raise Fog::AWS::RDS::AuthorizationAlreadyExists.slurp(error, match[2]) + match = Fog::AWS::Errors.match_error(error) + if match.empty? + case error.message + when 'Not Found' + raise Fog::AWS::RDS::NotFound.slurp(error, 'RDS Instance not found') else raise end else - case error.message - when 'Not Found' - raise Fog::AWS::RDS::NotFound.slurp(error, 'RDS Instance not found') - end - raise + raise case match[:code] + when 'DBInstanceNotFound', 'DBParameterGroupNotFound', 'DBSnapshotNotFound', 'DBSecurityGroupNotFound' + Fog::AWS::RDS::NotFound.slurp(error, match[:message]) + when 'DBParameterGroupAlreadyExists' + Fog::AWS::RDS::IdentifierTaken.slurp(error, match[:message]) + when 'AuthorizationAlreadyExists' + Fog::AWS::RDS::AuthorizationAlreadyExists.slurp(error, match[:message]) + else + Fog::Compute::AWS::Error.slurp(error, "#{match[:code]} => #{match[:message]}") + end end end - - response end end diff --git a/lib/fog/aws/sts.rb b/lib/fog/aws/sts.rb index a3dbbf9b1..8a8af8816 100644 --- a/lib/fog/aws/sts.rb +++ b/lib/fog/aws/sts.rb @@ -102,7 +102,7 @@ module Fog ) begin - response = @connection.request({ + @connection.request({ :body => body, :expects => 200, :idempotent => idempotent, @@ -111,23 +111,17 @@ module Fog :method => 'POST', :parser => parser }) - - response rescue Excon::Errors::HTTPStatusError => error - if match = error.response.body.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m) - case match[1] - when 'EntityAlreadyExists', 'KeyPairMismatch', 'LimitExceeded', 'MalformedCertificate', 'ValidationError' - raise Fog::AWS::STS.const_get(match[1]).slurp(error, match[2]) - else - raise Fog::AWS::STS::Error.slurp(error, "#{match[1]} => #{match[2]}") if match[1] - raise - end - else - raise - end + match = Fog::AWS::Errors.match_error(error) + raise if match.empty? + raise case match[:code] + when 'EntityAlreadyExists', 'KeyPairMismatch', 'LimitExceeded', 'MalformedCertificate', 'ValidationError' + Fog::AWS::STS.const_get(match[:code]).slurp(error, match[:message]) + else + Fog::AWS::STS::Error.slurp(error, "#{match[:code]} => #{match[:message]}") + end end - end end From e160a341e9cb1dfa73cbfc7f7397cf2345b9b396 Mon Sep 17 00:00:00 2001 From: James Bence Date: Tue, 2 Jul 2013 19:48:10 -0700 Subject: [PATCH 3/6] Remove code from other branch-in-progress --- lib/fog/aws/rds.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/fog/aws/rds.rb b/lib/fog/aws/rds.rb index 8d605d1ec..6d25abecc 100644 --- a/lib/fog/aws/rds.rb +++ b/lib/fog/aws/rds.rb @@ -51,15 +51,11 @@ module Fog request :describe_db_subnet_groups # TODO: :delete_db_subnet_group, :modify_db_subnet_group - request :describe_db_log_files - model_path 'fog/aws/models/rds' model :server collection :servers - model :snapshot collection :snapshots - model :parameter_group collection :parameter_groups @@ -72,9 +68,6 @@ module Fog model :subnet_group collection :subnet_groups - model :log_file - collection :log_files - class Mock def self.data From 041ca02c4c4591b1419d40d013dc4a5b45c3ad9a Mon Sep 17 00:00:00 2001 From: James Bence Date: Tue, 2 Jul 2013 19:49:33 -0700 Subject: [PATCH 4/6] Remove mistaken version update --- lib/fog/aws/rds.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fog/aws/rds.rb b/lib/fog/aws/rds.rb index 6d25abecc..d8f48eec1 100644 --- a/lib/fog/aws/rds.rb +++ b/lib/fog/aws/rds.rb @@ -191,7 +191,7 @@ module Fog :host => @host, :path => @path, :port => @port, - :version => '2013-05-15' #'2012-09-17' #'2011-04-01' + :version => '2012-09-17' #'2011-04-01' } ) From 4781d517385e819eeca0ba19ad2c87de5b5935e1 Mon Sep 17 00:00:00 2001 From: James Bence Date: Wed, 3 Jul 2013 08:18:29 -0700 Subject: [PATCH 5/6] Construct hash with => (for 1.8.7) --- lib/fog/aws.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fog/aws.rb b/lib/fog/aws.rb index dbc59f9a3..36e97d6e1 100644 --- a/lib/fog/aws.rb +++ b/lib/fog/aws.rb @@ -307,7 +307,7 @@ module Fog matcher = lambda {|s| s.match(/(?:.*(.*)<\/Code>)(?:.*(.*)<\/Message>)/m)} [error.message, error.response.body].each(&Proc.new {|s| match = matcher.call(s) - return {code: match[1].split('.').last, message: match[2]} if match + return {:code => match[1].split('.').last, :message => match[2]} if match }) {} # we did not match the message or response body end From f5dfebec84ebc3b5e3ff7c9d7ea3f3ee07e66506 Mon Sep 17 00:00:00 2001 From: James Bence Date: Wed, 3 Jul 2013 10:00:07 -0700 Subject: [PATCH 6/6] Use specific error classes, not generic Fog::Compute::AWS::Error --- lib/fog/aws/auto_scaling.rb | 2 +- lib/fog/aws/elasticache.rb | 2 +- lib/fog/aws/elb.rb | 2 +- lib/fog/aws/rds.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fog/aws/auto_scaling.rb b/lib/fog/aws/auto_scaling.rb index 63d189ff4..c46e2afb6 100644 --- a/lib/fog/aws/auto_scaling.rb +++ b/lib/fog/aws/auto_scaling.rb @@ -163,7 +163,7 @@ module Fog when 'ValidationError' Fog::AWS::AutoScaling::ValidationError.slurp(error, match[:message]) else - Fog::Compute::AWS::Error.slurp(error, "#{match[:code]} => #{match[:message]}") + Fog::AWS::AutoScaling::Error.slurp(error, "#{match[:code]} => #{match[:message]}") end end end diff --git a/lib/fog/aws/elasticache.rb b/lib/fog/aws/elasticache.rb index 2db7e5f2c..e510edd01 100644 --- a/lib/fog/aws/elasticache.rb +++ b/lib/fog/aws/elasticache.rb @@ -114,7 +114,7 @@ module Fog when 'InvalidParameterValue' Fog::AWS::Elasticache::InvalidInstance.slurp(error, match[:message]) else - Fog::AWS::Compute::Error.slurp(error, "#{match[:code]} => #{match[:message]}") + Fog::AWS::Elasticache::Error.slurp(error, "#{match[:code]} => #{match[:message]}") end end diff --git a/lib/fog/aws/elb.rb b/lib/fog/aws/elb.rb index 4f29cf70f..e9c835a6e 100644 --- a/lib/fog/aws/elb.rb +++ b/lib/fog/aws/elb.rb @@ -218,7 +218,7 @@ module Fog when 'ValidationError' Fog::AWS::ELB::ValidationError.slurp(error, match[:message]) else - Fog::Compute::AWS::Error.slurp(error, "#{match[:code]} => #{match[:message]}") + Fog::AWS::ELB::Error.slurp(error, "#{match[:code]} => #{match[:message]}") end end end diff --git a/lib/fog/aws/rds.rb b/lib/fog/aws/rds.rb index d8f48eec1..ecde49cf0 100644 --- a/lib/fog/aws/rds.rb +++ b/lib/fog/aws/rds.rb @@ -223,7 +223,7 @@ module Fog when 'AuthorizationAlreadyExists' Fog::AWS::RDS::AuthorizationAlreadyExists.slurp(error, match[:message]) else - Fog::Compute::AWS::Error.slurp(error, "#{match[:code]} => #{match[:message]}") + Fog::AWS::RDS::Error.slurp(error, "#{match[:code]} => #{match[:message]}") end end end