s3dol.errors¶
The s3dol error taxonomy and the single error-translation seam.
Design record: misc/docs/decisions/0004-error-taxonomy.md (the taxonomy, the
(operation, code, status) classification, the 403 policy, ObjectArchived)
and misc/docs/decisions/0012-credential-and-endpoint-resolution.md (the
ConfigurationError tree and the S3DolWarning tree).
Three rules govern this module:
One seam.
translate_s3_errors()is the only place in the package that catches botocore exceptions. Everything else propagates.**Auth, config and transport errors are never translated to
KeyError.** A missing permission must not look like a missing key.**Classification keys on
(operation, code, status), never on exception type.** HEAD responses have no body, so botocore’s modelled exceptions (client.exceptions.NoSuchKey…) never fire for them.
Everything classification-related here is pure: classify_client_error()
takes plain values (or a synthesized ClientError) and touches no network,
so the bulk of error tests are tier-1 unit tests — including body-less HEAD
errors, which moto cannot produce.
>>> classify_client_error('GetObject', 'NoSuchKey', 404).kind
'object_absent'
>>> classify_client_error('HeadObject', '404', 404).kind # HEAD is ambiguous
'ambiguous_head'
>>> classify_client_error('GetObject', 'AccessDenied', 403).kind
'access_denied'
Module Attributes
Kinds a classified error can be. |
|
|
|
The default classification table (ADR-0004 §2, measured against botocore). |
Functions
|
Classify a backend error by |
|
The |
|
Redact signed-URL query secrets from |
|
A URL safe to display: userinfo, query and fragment removed. |
|
The HTTP status of a botocore |
|
Translate a botocore |
|
The one seam: decorate a Layer B method so botocore's |
|
Generator/inline form of the seam, for code the decorator cannot wrap ( |
Classes
|
The result of classifying a backend error. |
Exceptions
Permission denied. |
|
Resolution is legal but ambiguous (e.g. a named preset whose endpoint, supplied from the environment, matches no known host pattern). |
|
Anonymous access was used as a fallback (reserved for a future |
|
Refusal to delete a non-empty bucket. |
|
The bucket is absent. |
|
A construction- or resolution-time misconfiguration (ADR-0012 D1). |
|
Credentials are missing, expired, or invalid. |
|
An endpoint URL failed hygiene checks (userinfo/query/fragment — ADR-0012 D4: a URL is the residual credential carrier). |
|
The key is syntactically invalid (checked before the wire). |
|
The named preset needs an endpoint (or endpoint parameters) that nothing supplied (ADR-0012 C1). |
|
A preset's endpoint template has an unbound required parameter, so the row contributes no endpoint rung (ADR-0012 C1). |
|
The operation is not supported by this provider (names both). |
|
|
The object exists but is archived (e.g. Glacier) and cannot be read now. |
The object is absent. |
|
An explicit argument contradicts a pinned (verified) preset value. |
|
The resolved endpoint's host matches a different provider's patterns than the preset you named (ADR-0012 C2). |
|
v1 resolves this call differently than v0 would have (ADR-0012 D7). |
|
Base of every s3dol warning. |
|
Base of every s3dol exception — |
|
|
A bulk operation partially failed (ADR-0010 §2). |
A parameter was bound that the preset's templates do not use. |
- exception s3dol.errors.AccessDenied[source]¶
Bases:
S3ErrorPermission denied. Not a
KeyError— a missing permission must not look like a missing key (ADR-0004 §1/§3).
- exception s3dol.errors.AmbiguousResolution[source]¶
Bases:
S3DolWarningResolution is legal but ambiguous (e.g. a named preset whose endpoint, supplied from the environment, matches no known host pattern).
- exception s3dol.errors.AnonymousFallback[source]¶
Bases:
S3DolWarningAnonymous access was used as a fallback (reserved for a future
anon='auto'— ADR-0012 D5 defers that feature to v1.x).
- exception s3dol.errors.BucketNotEmpty[source]¶
Bases:
S3ErrorRefusal to delete a non-empty bucket. Use
s3dol.delete_bucket(endpoint, name, force=True)for the explicit cascading form (ADR-0010 §3).
- exception s3dol.errors.BucketNotFound[source]¶
Bases:
S3Error,_InformativeKeyErrorThe bucket is absent.
Still a
KeyError: for an object operation it is a key-space problem for the caller; for a bucket operation it is the key of the endpoint mapping.
- class s3dol.errors.Classified(kind, exception_type=None)[source]¶
Bases:
objectThe result of classifying a backend error.
- exception s3dol.errors.ConfigurationError[source]¶
Bases:
S3Error,ValueErrorA construction- or resolution-time misconfiguration (ADR-0012 D1).
- exception s3dol.errors.CredentialsError[source]¶
Bases:
S3ErrorCredentials are missing, expired, or invalid.
- s3dol.errors.DEFAULT_RULES: tuple[tuple[tuple[Optional[str], Optional[str], Optional[int]], str], ...] = (((None, 'NoSuchKey', None), 'object_absent'), ((None, 'NoSuchBucket', None), 'bucket_absent'), ((None, 'NoSuchUpload', None), 'object_absent'), (('HeadObject', '404', 404), 'ambiguous_head'), (('HeadBucket', '404', 404), 'bucket_absent'), (('HeadObject', '404', None), 'ambiguous_head'), (('HeadBucket', '404', None), 'bucket_absent'), (('HeadObject', None, 405), 'delete_marker'), ((None, None, 301), 'wrong_region'), ((None, 'PermanentRedirect', None), 'wrong_region'), ((None, 'AuthorizationHeaderMalformed', None), 'wrong_region'), ((None, 'InvalidObjectState', None), 'archived'), ((None, 'RequestTimeTooSkewed', None), 'credentials'), ((None, 'RequestExpired', None), 'credentials'), ((None, 'AuthorizationQueryParametersError', None), 'credentials'), ((None, 'ExpiredToken', None), 'credentials'), ((None, 'InvalidAccessKeyId', None), 'credentials'), ((None, 'SignatureDoesNotMatch', None), 'credentials'), ((None, 'TokenRefreshRequired', None), 'credentials'), ((None, 'AccessDenied', None), 'access_denied'), ((None, 'AllAccessDisabled', None), 'access_denied'), ((None, '403', 403), 'access_denied'), ((None, None, 403), 'access_denied'), ((None, 'KeyTooLongError', None), 'invalid_key'), ((None, 'SlowDown', None), 'transient'), ((None, 'RequestTimeout', None), 'transient'), ((None, 'ServiceUnavailable', None), 'transient'), ((None, 'InternalError', None), 'transient'), ((None, None, 503), 'transient'))¶
The default classification table (ADR-0004 §2, measured against botocore).
- exception s3dol.errors.InvalidEndpoint[source]¶
Bases:
ConfigurationErrorAn endpoint URL failed hygiene checks (userinfo/query/fragment — ADR-0012 D4: a URL is the residual credential carrier).
- s3dol.errors.KINDS = ('object_absent', 'bucket_absent', 'ambiguous_head', 'access_denied', 'credentials', 'invalid_key', 'archived', 'not_supported', 'wrong_region', 'delete_marker', 'transient', 'unknown')¶
Kinds a classified error can be. Layer B maps kinds to behaviour; in particular
ambiguous_headtriggers the one-HeadBucketdisambiguation of ADR-0004 §2 (HEAD has no body, so a missing key and a missing bucket are both('404', 404)on real AWS).
- exception s3dol.errors.KeyNotValid[source]¶
Bases:
S3Error,_InformativeKeyError,ValueErrorThe key is syntactically invalid (checked before the wire).
Inherits from both
KeyErrorandValueErrordeliberately, so eitherexceptworks. NamedKeyNotValid(notKeyValidationError) because dol already ships two different classes calledKeyValidationError(ADR-0004 §5).
- exception s3dol.errors.MissingEndpoint[source]¶
Bases:
ConfigurationErrorThe named preset needs an endpoint (or endpoint parameters) that nothing supplied (ADR-0012 C1).
- exception s3dol.errors.MissingPresetParam[source]¶
Bases:
MissingEndpointA preset’s endpoint template has an unbound required parameter, so the row contributes no endpoint rung (ADR-0012 C1). A
MissingEndpoint, so eitherexceptworks.
- exception s3dol.errors.NotSupported[source]¶
Bases:
S3ErrorThe operation is not supported by this provider (names both).
- exception s3dol.errors.ObjectArchived(message, *, storage_class=None, restore_status=None, restore=None)[source]¶
Bases:
S3Error,_InformativeKeyErrorThe object exists but is archived (e.g. Glacier) and cannot be read now.
A
KeyError, deliberately and arguably (ADR-0004 §4):k in storestaysTrue, butstore[k]fails as aKeyErrorso thatstore.get(k, default)degrades to the not-available branch. Note that only the defaulted accessors degrade —dict(store),.items()andMapping.__eq__still raise.setdefault/popare overridden in the store to re-raise this instead of silently overwriting the archived object.
- exception s3dol.errors.ObjectNotFound[source]¶
Bases:
S3Error,_InformativeKeyErrorThe object is absent. The Mapping contract’s
KeyError.
- exception s3dol.errors.PresetConflict[source]¶
Bases:
ConfigurationErrorAn explicit argument contradicts a pinned (verified) preset value.
- exception s3dol.errors.PresetHostMismatch[source]¶
Bases:
ConfigurationErrorThe resolved endpoint’s host matches a different provider’s patterns than the preset you named (ADR-0012 C2).
- s3dol.errors.Rule¶
((operation, code, status), kind).Noneis a wildcard. First match wins; more specific rows come first.- Type:
Rule rows
alias of
tuple[tuple[str|None,str|None,int|None],str]
- exception s3dol.errors.S3DolResolutionChanged[source]¶
Bases:
S3DolWarningv1 resolves this call differently than v0 would have (ADR-0012 D7). Emitted by the compat shim; dies with it.
- exception s3dol.errors.S3DolWarning[source]¶
Bases:
UserWarningBase of every s3dol warning.
- exception s3dol.errors.S3Error[source]¶
Bases:
ExceptionBase of every s3dol exception —
except S3Errorcatches the package.
- exception s3dol.errors.S3PartialFailure(message, *, succeeded, failures)[source]¶
Bases:
S3ErrorA bulk operation partially failed (ADR-0010 §2).
Not an
ExceptionGroup— the package supports Python 3.10.- succeeded¶
keys the backend reported as deleted (absent keys are reported as deleted too — S3’s semantics, documented, not hidden).
- failures¶
mapping of key -> the error for that key.
- exception s3dol.errors.UnknownPresetParam[source]¶
Bases:
ConfigurationErrorA parameter was bound that the preset’s templates do not use.
- s3dol.errors.classify_client_error(operation, code, status, *, overrides=())[source]¶
Classify a backend error by
(operation, code, status).overridesrows (typically from a preset) are consulted first, so a provider divergence is a table row, never a code branch.>>> classify_client_error('HeadBucket', None, 400, ... overrides=((('HeadBucket', None, 400), 'bucket_absent'),)).kind 'bucket_absent'
- Return type:
- s3dol.errors.redact(text)[source]¶
Redact signed-URL query secrets from
text.Error messages may name the operation, bucket, key, endpoint and code, but never a credential, token, or signed URL — redaction is a tested function, not a convention (ADR-0004 §7).
>>> redact('https://b.s3.amazonaws.com/k?X-Amz-Signature=abc123&x=1') 'https://b.s3.amazonaws.com/k?X-Amz-Signature=REDACTED&x=1'
- Return type:
- s3dol.errors.redact_url(url)[source]¶
A URL safe to display: userinfo, query and fragment removed.
A URL is the residual credential carrier (ADR-0012 D4). Endpoint hygiene refuses those shapes for values s3dol is given, but an endpoint read from
AWS_ENDPOINT_URL_S3or an aws-config profile is not ours to refuse — it must merely never be echoed intact.>>> redact_url('https://user:pw@minio.internal:9000/x?sig=abc#f') 'https://REDACTED@minio.internal:9000/x?<redacted>'
- s3dol.errors.translate_client_error(error, *, operation, bucket=None, key=None, endpoint=None, overrides=(), deny_means_absent=False, head_ambiguity_resolver=None)[source]¶
Translate a botocore
ClientErrorinto the s3dol taxonomy.Returns the replacement exception, or
Nonemeaning *propagate the original* (transient/unknown — rule 2 of the module docstring).head_ambiguity_resolverresolves the body-lessHeadObject404 (ADR-0004 §2): it returnsTrueiff the bucket is known reachable, in which case the miss really is the object’s. It is only called for the ambiguous case, so the common path costs nothing.deny_means_absent=Trueclassifies an object-op 403 asObjectNotFound— for deployments knowingly running the canonical least-privilege policy that omitss3:ListBucket(ADR-0004 §3).
- s3dol.errors.translate_s3_errors(*, operation, key_arg=None, **translate_kwargs)[source]¶
The one seam: decorate a Layer B method so botocore’s
ClientErrorbecomes the s3dol taxonomy (ADR-0004 §1).key_argnames the decorated function’s key parameter (resolved via the call’s kwargs/positionals — never an attribute, so the key is not lost the way azuredol’skey_arg='blob'loses it). The store instance is expected to provide_error_context()returningdict(bucket=..., endpoint=..., overrides=..., deny_means_absent=..., head_ambiguity_resolver=...)— Layer B owns that context.
- s3dol.errors.translating_s3_errors(store, *, operation, key=None, **translate_kwargs)[source]¶
Generator/inline form of the seam, for code the decorator cannot wrap (
__iter__bodies: a decorated generator function returns its generator before the body runs, so the decorator’sexceptnever fires).Same contract as
translate_s3_errors(); the store supplies_error_context().