Skip to content

Error.Code returns HTTP status or wrong spelling for SSM/Lambda/IAM/S3 not-found #392

Closed

Description

@scttfrdmn

Summary

Several services return the bare HTTP status ("404") or a near-miss spelling in
Error.Code, where AWS returns a documented symbolic code. botocore surfaces
Error.Code verbatim as ClientError.response["Error"]["Code"], and that string is
what every except ClientError branch in real client code compares against — so a
numeric code silently defeats the caller's error handling.

Reproduction

Against ghcr.io/scttfrdmn/substrate:0.76.0, e.response["Error"]["Code"]:

Call substrate AWS
ssm.get_parameter(Name="/nope") "404" ParameterNotFound
lambda.get_function(FunctionName="nope") "404" ResourceNotFoundException
iam.get_role(RoleName="nope") "NoSuchEntityException" NoSuchEntity
s3.get_object(Bucket=<missing bucket>, Key="k") "NoSuchKey" NoSuchBucket

The IAM one is subtle: NoSuchEntityException is the shape name in the API
model, while the wire error code is NoSuchEntity. (lambda genuinely does use
the ...Exception suffix on the wire, so the two services differ.)

The S3 case conflates two distinct conditions — a missing bucket and a missing key
in an existing bucket both return NoSuchKey, so a caller cannot tell "someone
deleted my bucket" from "this object isn't written yet".

Expected

Error.Code carries the documented symbolic code for each service. HTTP status
stays in ResponseMetadata.HTTPStatusCode, where callers that want it can find it.

Why it matters

From parsl-ephemeral-aws, the read-then-create idiom that Parameter Store state
persistence is built on:

try:
    self.ssm_client.put_parameter(Name=name, Value=v, Overwrite=True)
except ClientError as e:
    if e.response["Error"]["Code"] == "ParameterNotFound":
        self.ssm_client.put_parameter(Name=name, Value=v, Tags=[...])  # create with tags
    else:
        raise

With Code == "404" the branch is skipped and the exception propagates, so the
create-with-tags path cannot be tested at all. Same structure appears for
NoSuchEntity (IAM role/instance-profile creation, 7 call sites) and NoSuchKey
(S3 state store, 3 call sites).

These are the codes that distinguish "not there yet, create it" from "real
failure" — the branch an emulator is most useful for exercising.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: hightype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions