1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
|
# frozen_string_literal: true
module Aws
module Errors
class NonSupportedRubyVersionError < RuntimeError; end
# The base class for all errors returned by an Amazon Web Service.
# All ~400 level client errors and ~500 level server errors are raised
# as service errors. This indicates it was an error returned from the
# service and not one generated by the client.
class ServiceError < RuntimeError
# @param [Seahorse::Client::RequestContext] context
# @param [String] message
# @param [Aws::Structure] data
def initialize(context, message, data = Aws::EmptyStructure.new)
@code = self.class.code
@message = message if message && !message.empty?
@context = context
@data = data
super(message)
end
# @return [String]
attr_reader :code
# @return [Seahorse::Client::RequestContext] The context of the request
# that triggered the remote service to return this error.
attr_reader :context
# @return [Aws::Structure]
attr_reader :data
class << self
# @return [String]
attr_accessor :code
end
# @api private undocumented
def retryable?
false
end
# @api private undocumented
def throttling?
false
end
end
# Raised when InstanceProfileCredentialsProvider or
# EcsCredentialsProvider fails to parse the metadata response after retries
class MetadataParserError < RuntimeError
def initialize(*args)
msg = 'Failed to parse metadata service response.'
super(msg)
end
end
# Raised when a `streaming` operation has `requiresLength` trait
# enabled but request payload size/length cannot be calculated
class MissingContentLength < RuntimeError
def initialize(*args)
msg = 'Required `Content-Length` value missing for the request.'
super(msg)
end
end
# Rasied when endpoint discovery failed for operations
# that requires endpoints from endpoint discovery
class EndpointDiscoveryError < RuntimeError
def initialize(*args)
msg = 'Endpoint discovery failed for the operation or discovered endpoint is not working, '\
'request will keep failing until endpoint discovery succeeds or :endpoint option is provided.'
super(msg)
end
end
# raised when hostLabel member is not provided
# at operation input when endpoint trait is available
# with 'hostPrefix' requirement
class MissingEndpointHostLabelValue < RuntimeError
def initialize(name)
msg = "Missing required parameter #{name} to construct"\
' endpoint host prefix. You can disable host prefix by'\
' setting :disable_host_prefix_injection to `true`.'
super(msg)
end
end
# Raised when attempting to #signal an event before
# making an async request
class SignalEventError < RuntimeError; end
# Raised when EventStream Parser failed to parse
# a raw event message
class EventStreamParserError < RuntimeError; end
# Raise when EventStream Builder failed to build
# an event message with parameters provided
class EventStreamBuilderError < RuntimeError; end
# Error event in an event stream which has event_type :error
# error code and error message can be retrieved when available.
#
# example usage:
#
# client.stream_foo(name: 'bar') do |event|
# stream.on_error_event do |event|
# puts "Error #{event.error_code}: #{event.error_message}"
# raise event
# end
# end
#
class EventError < RuntimeError
def initialize(event_type, code, message)
@event_type = event_type
@error_code = code
@error_message = message
end
# @return [Symbol]
attr_reader :event_type
# @return [String]
attr_reader :error_code
# @return [String]
attr_reader :error_message
end
# Raised when ARN string input doesn't follow the standard:
# https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#genref-arns
class InvalidARNError < RuntimeError; end
# Raised when the region from the ARN string is different from the :region
# configured on the service client.
class InvalidARNRegionError < RuntimeError
def initialize(*args)
msg = 'ARN region is different from the configured client region.'
super(msg)
end
end
# Raised when the partition of the ARN region is different than the
# partition of the :region configured on the service client.
class InvalidARNPartitionError < RuntimeError
def initialize(*args)
msg = 'ARN region partition is different from the configured '\
'client region partition.'
super(msg)
end
end
# Various plugins perform client-side checksums of responses.
# This error indicates a checksum failed.
class ChecksumError < RuntimeError; end
# Raised when a client is constructed and the specified shared
# credentials profile does not exist.
class NoSuchProfileError < RuntimeError; end
# Raised when a client is constructed, where Assume Role credentials are
# expected, and there is no source profile specified.
class NoSourceProfileError < RuntimeError; end
# Raised when a client is constructed with Assume Role credentials using
# a credential_source, and that source type is unsupported.
class InvalidCredentialSourceError < RuntimeError; end
# Raised when a client is constructed with Assume Role credentials, but
# the profile has both source_profile and credential_source.
class CredentialSourceConflictError < RuntimeError; end
# Raised when a client is constructed with Assume Role credentials using
# a credential_source, and that source doesn't provide credentials.
class NoSourceCredentialsError < RuntimeError; end
# Raised when a client is constructed and credentials are not
# set, or the set credentials are empty.
class MissingCredentialsError < RuntimeError
def initialize(*args)
msg = 'unable to sign request without credentials set'
super(msg)
end
end
# Raised when :web_identity_token_file parameter is not
# provided or the file doesn't exist when initializing
# AssumeRoleWebIdentityCredentials credential provider
class MissingWebIdentityTokenFile < RuntimeError
def initialize(*args)
msg = 'Missing :web_identity_token_file parameter or'\
' invalid file path provided for'\
' Aws::AssumeRoleWebIdentityCredentials provider'
super(msg)
end
end
# Raised when a credentials provider process returns a JSON
# payload with either invalid version number or malformed contents
class InvalidProcessCredentialsPayload < RuntimeError; end
# Raised when a client is constructed and region is not specified.
class MissingRegionError < ArgumentError
def initialize(*args)
msg = 'No region was provided. Configure the `:region` option or '\
"export the region name to ENV['AWS_REGION']"
super(msg)
end
end
# Raised when a client is contsructed and the region is not valid.
class InvalidRegionError < ArgumentError
def initialize(*args)
super(<<-MSG)
Invalid `:region` option was provided.
* Not every service is available in every region.
* Never suffix region names with availability zones.
Use "us-east-1", not "us-east-1a"
Known AWS regions include (not specific to this service):
#{possible_regions}
MSG
end
private
def possible_regions
Aws.partitions.each_with_object([]) do |partition, region_names|
partition.regions.each do |region|
region_names << region.name
end
end.join("\n")
end
end
# Raised when attempting to connect to an endpoint and a `SocketError`
# is received from the HTTP client. This error is typically the result
# of configuring an invalid `:region`.
class NoSuchEndpointError < RuntimeError
def initialize(options = {})
@context = options[:context]
@endpoint = @context.http_request.endpoint
@original_error = options[:original_error]
super(<<-MSG)
Encountered a `SocketError` while attempting to connect to:
#{endpoint}
This is typically the result of an invalid `:region` option or a
poorly formatted `:endpoint` option.
* Avoid configuring the `:endpoint` option directly. Endpoints are constructed
from the `:region`. The `:endpoint` option is reserved for certain services
or for connecting to non-standard test endpoints.
* Not every service is available in every region.
* Never suffix region names with availability zones.
Use "us-east-1", not "us-east-1a"
Known AWS regions include (not specific to this service):
#{possible_regions}
MSG
end
attr_reader :context
attr_reader :endpoint
attr_reader :original_error
private
def possible_regions
Aws.partitions.each_with_object([]) do |partition, region_names|
partition.regions.each do |region|
region_names << region.name
end
end.join("\n")
end
end
# Raised when attempting to retry a request
# and no capacity is available to retry (See adaptive retry_mode)
class RetryCapacityNotAvailableError < RuntimeError
def initialize(*args)
msg = 'Insufficient client side capacity available to retry request.'
super(msg)
end
end
# This module is mixed into another module, providing dynamic
# error classes. Error classes all inherit from {ServiceError}.
#
# # creates and returns the class
# Aws::S3::Errors::MyNewErrorClass
#
# Since the complete list of possible AWS errors returned by services
# is not known, this allows us to create them as needed. This also
# allows users to rescue errors by class without them being concrete
# classes beforehand.
#
# @api private
module DynamicErrors
def self.extended(submodule)
submodule.instance_variable_set('@const_set_mutex', Mutex.new)
submodule.const_set(:ServiceError, Class.new(ServiceError))
end
def const_missing(constant)
set_error_constant(constant)
end
# Given the name of a service and an error code, this method
# returns an error class (that extends {ServiceError}.
#
# Aws::S3::Errors.error_class('NoSuchBucket').new
# #=> #<Aws::S3::Errors::NoSuchBucket>
#
# @api private
def error_class(error_code)
constant = error_class_constant(error_code)
if error_const_set?(constant)
# modeled error class exist
# set code attribute
err_class = const_get(constant)
err_class.code = constant.to_s
err_class
else
set_error_constant(constant)
end
end
private
# Convert an error code to an error class name/constant.
# This requires filtering non-safe characters from the constant
# name and ensuring it begins with an uppercase letter.
# @param [String] error_code
# @return [Symbol] Returns a symbolized constant name for the given
# `error_code`.
def error_class_constant(error_code)
constant = error_code.to_s
constant = constant.gsub(/https?:.*$/, '')
constant = constant.gsub(/[^a-zA-Z0-9]/, '')
constant = 'Error' + constant unless constant.match(/^[a-z]/i)
constant = constant[0].upcase + constant[1..-1]
constant.to_sym
end
def set_error_constant(constant)
@const_set_mutex.synchronize do
# Ensure the const was not defined while blocked by the mutex
if error_const_set?(constant)
const_get(constant)
else
error_class = Class.new(const_get(:ServiceError))
error_class.code = constant.to_s
const_set(constant, error_class)
end
end
end
def error_const_set?(constant)
# Purposefully not using #const_defined? as that method returns true
# for constants not defined directly in the current module.
constants.include?(constant.to_sym)
end
end
end
end
|