You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.
Module: AWS::Core::LazyErrorClasses
- Included in:
- AutoScaling::Errors, AWS::CloudFormation::Errors, AWS::CloudFront::Errors, AWS::CloudSearch::Errors, AWS::CloudTrail::Errors, AWS::CloudWatch::Errors, DataPipeline::Errors, DynamoDB::Errors, EC2::Errors, ELB::Errors, EMR::Errors, ElastiCache::Errors, ElasticBeanstalk::Errors, ElasticTranscoder::Errors, Glacier::Errors, IAM::Errors, ImportExport::Errors, Kinesis::Errors, OpsWorks::Errors, RDS::Errors, Redshift::Errors, Route53::Errors, S3::Errors, SNS::Errors, SQS::Errors, STS::Errors, SimpleEmailService::Errors, SimpleWorkflow::Errors, StorageGateway::Errors, Support::Errors
- Defined in:
- lib/aws/core/lazy_error_classes.rb
Overview
Provides lazy creation of error classes via #const_missing.
Extend this module provides 3 benefits to another module:
- A method that accepts strings and returns error classes.
- Thread-safe dynamic error class creation via #const_missing
- An error grammar for parsing AWS xml errors
Here is an example of how it works:
Class Foo
module Errors
extend AWS::Core::LazyErrorClasses
end
end
Foo::Errors.error_class('NoSuchKey')
#=> Foo::Errors::NoSuckKey
Foo::Errors.error_class('Nested.Error.Klasses')
#=> Foo::Errors::Nested::Error::Klasses
The errors returned from #error_class are subclasses of Errors::Base.
Constant Summary
- BASE_ERROR_GRAMMAR =
This grammar parses the defualt AWS XML error format
XML::Grammar.customize do element("Error") do ignore end end
Instance Method Summary collapse
-
#const_missing(constant) ⇒ nil
Defines a new error class.
-
#error_class(code) ⇒ Class
Converts the error code into an error class constant.
Instance Method Details
#const_missing(constant) ⇒ nil
Defines a new error class.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/aws/core/lazy_error_classes.rb', line 68 def const_missing constant const_missing_mutex.synchronize do # It's possible the constant was defined by another thread while # this thread was waiting on the mutex, check before setting. if error_const_set?(constant) const_get(constant) else const_set(constant, Class.new(Errors::Base) { extend LazyErrorClasses }) end end end |
#error_class(code) ⇒ Class
Converts the error code into an error class constant.
AWS::EC2::Errors.error_class('Non.Existent.Error')
#=> AWS::EC2::Errors::Non::Existent::Error
89 90 91 |
# File 'lib/aws/core/lazy_error_classes.rb', line 89 def error_class code module_eval("#{self}::#{code.gsub('.Range','Range').gsub(".","::")}") end |