Skip to content

fix(errors): a request body that will not parse answers a published code (#950) - #1005

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/parse-guard-codes-inventory-950
Sep 17, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/parse-guard-codes-inventory-950

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Sep 17, 2026 •

Copy link
Copy Markdown
Owner

Closes #950.

The rest of the class #1003 opened at Step Functions and Systems Manager, taken to every remaining
service in the tree. Eighty-three more sites in twelve services answered an error code their own
operation does not publish
for a request body that would not parse, and twenty-two of them handed
the caller encoding/json's error text as the message
.

All eighty-three already answered HTTP 400, and 400 is what every published counterpart carries.
So the whole class was invisible to #923's status audit: it is a code-string and message defect
throughout, and the status half of the pass changed nothing.

The rule, because AWS does not give one answer

  1. If every operation carrying a guard publishes the same input-validation code in its own Errors
    section, use that code.
  2. Otherwise fall back to the service's common-errors page, which is where an error belonging to no
    single operation belongs.

Step 1 is the stronger citation — the page that receives the request names it. Step 2 exists because a
body that will not parse belongs to no operation: substrate cannot know which parameter was wrong,
since nothing was decoded.

Step 1 settled Kinesis (InvalidArgumentException, all sixteen pages), Lambda
(InvalidParameterValueException, all four), EFS (BadRequest, all four), Service Quotas
(IllegalArgumentException, all four), Budgets (InvalidParameterException, all five), SES v2
(BadRequestException, all five) and Batch (ClientException). Step 2 settled EventBridge, SageMaker,
ACM, Firehose and Cost Explorer, none of which publishes a validation code on any guarded operation.

The rule is why two services under one reference legitimately differ: Budgets and Cost Explorer
share a common-errors page, but Budgets publishes InvalidParameterException on all five of its
guarded operations and Cost Explorer publishes nothing on any of its three. It is also why Firehose
loses InvalidArgumentException even at the one site that publishes it
— a missing
DeliveryStreamName is one condition, and answering it with two codes depending on which operation
received it is the failure mode a uniform choice exists to avoid.

Firehose is also why every guarded operation was checked, not a representative one

InvalidArgumentException is published for CreateDeliveryStream — the page anyone would open first —
and for neither of the other two, which publish only ResourceNotFoundException and
ResourceInUseException. Taking the obvious replacement from the representative page would have been
wrong at two of three sites, which is this defect relocated.

Three services publish no common-errors page, and one publishes nothing at all

EFS, Batch and API Gateway v2 have no page to fall back to, so for all three step 1 was the only route
available — and it was open in all three. That is the strongest argument for preferring it: a rule that
depends on a page three services do not have is a rule with three holes in it.

MSK kept BadRequest. It has no common-errors page, its operation pages carry no Errors
section
(clusters.html documents response codes only, and the Error schema it names has members
{message, invalidParameter} with no Code member), and CreateClusterV2 — one of the two operations
carrying a guard — has no documentation page. So the code stays, recorded in msk_errors.go as
substrate's reading rather than presented as modelled, the same treatment CloudWatch's
SerializationException already gets. Inventing a code on no evidence would be worse than keeping one
that has at least shipped. Its eleven sites now route through one constructor, so the code cannot come
to differ between the operation that creates a cluster and the one that describes it.

The message describes the request, not the emulator

Twenty-two sites across eight services passed encoding/json's own text through, so a caller was told
which Go struct field failed to unmarshal by an endpoint whose whole purpose is to look like AWS.
Service Quotas passed it bare, with no prefix at all. All twenty-two now report "the request body
is not valid JSON"
.

CloudWatch's CBOR arm is the one place a decoder's message is still appended, deliberately.
cborDecode's text is substrate's own and describes the wire — "cbor: 3 trailing byte(s) after the
top-level item"
— which is useful to the caller who wrote those bytes, where encoding/json's
describes Go. Only the WireJSONRPC arm leaked; the third arm's text comes from cwFlattenDoc and is
substrate's too.

A parse failure is not a missing member

Five sites tested if err != nil || body.X == "" and reported the missing member for both — four in
SageMaker, one in Bedrock Runtime's CreateModelInvocationJob, whose code was already right. They are
split, because the two conditions call for different fixes by the caller: one sends different bytes,
the other adds a member, and telling a caller their jobName is missing when their JSON is truncated
sends them to look at the wrong thing. Athena's and Secrets Manager's conflated sites are recorded in
docs/services.md rather than changed, because there the required member is the only member the
handler reads and the two answers coincide.

Two files that recorded an open question now record its answer

acm_certificate_arn.go's preamble said an unparseable body's code "belongs to ACM's common errors
rather than to any one operation's list"
and left settling it to a later pass. That guess was right,
and all six sites answer ValidationError/400. ValidationException is not the answer either, near as
the name is — ACM publishes it on five of six guarded operations and not on RequestCertificate —
which is why that plugin now carries two codes side by side on purpose.

batchClientError's doc comment claimed every Batch refusal for an unusable request went through it,
while SubmitJob and DescribeJobs bypassed it to answer InvalidParameterValue, a code on none of
the ten Batch pages. Both now route through it, so the comment is true.

Why a green suite held all 110 of them

A test that builds its request from a Go value is structurally incapable of reaching a parse guard,
because json.Marshal produces valid JSON by construction — and nothing in the suite handed the server
bytes, at any of the seventeen services involved. When 110 codes were corrected, exactly one existing
test failed
: the Service Quotas case that had asserted SerializationException deliberately, and
whose neighbour two functions below already documented IllegalArgumentException as "the code the
model declares for it on every Service Quotas operation"
.

emulator/invalid_body_inventory_test.go now sends bytes at 66 guarded operations in fourteen
services
,
one subtest per guarded operation rather than per sample, asserting the status and the code together
(a decoded error struct carries only the code; a consumer's retry logic branches on the status) and that
the message names no Go type. A mistyped REST path fails loudly rather than silently, since an unrouted
path answers UnknownOperationException/404.

Two of the 66 needed a resource to exist first, which is the one way a guard can be present, correct
and still untested: Lambda's AddPermission and TagResource look up the function before they
parse, so on an empty emulator both answer ResourceNotFoundException/404 and never reach the guard.
The test therefore creates a function and reads its ARN back off GetFunction rather than composing one.

Which of the two answers AWS gives is unverified, and this PR does not change the ordering. A case
is available either way — a caller naming a function that does not exist arguably wants to hear that,
while a REST-JSON frontend that deserializes before dispatch would refuse the body first — and no Lambda
page states the precedence; the Errors sections list both codes without ordering them. Filed as #1006,
where the real question is whether the answer generalises to every operation that reads state above its
guard, which is an inventory rather than two moved lines. #950's rule is about which code a guard
answers, not which guard runs first.

The member-complaint half is covered too, and five of it cannot be reached

codecov/patch reported 40 changed lines uncovered. All 40 are the corrected sites that are not
parse guards — the "+ N member" column of the inventory — so covering them was the fix rather than
a codecov workaround: leaving 40 changed error codes unverified would undercut this PR's own thesis.
35 now have a wire test, in nine services.

Those cases send {}, not a truncated body. That is the whole reason they cannot share the parse-guard
table: {} parses, so it travels past the guard and reaches the member check underneath, where
invalidBodyPayload stops one line earlier. Each asserts the message alongside the code, because once
every site in a service answers one code the message is the only thing telling them apart.

The remaining five cannot be reached by any request, and are recorded rather than tested.
parseKafkaOperation and parseSESv2Operation both open by trimming a trailing slash, so a request
naming an empty path parameter collapses onto the collection route one case earlier in the same switch:
GET /v1/clusters/ dispatches ListClusters, not DescribeCluster with an empty ARN. That makes MSK's
describeCluster, deleteCluster and describeClusterV2 checks and SES v2's getEmailIdentity and
deleteEmailIdentity checks dead code — their codes are corrected for consistency with their siblings,
but nothing can observe them, and each now says so at the line a reader would look for the guard.

MSK's getBootstrapBrokers and listNodes escape only because a literal segment follows the ARN, so
the empty parameter is interior rather than trailing and /v1/clusters//nodes reaches them — both are
covered by exactly those paths. parseEFSOperation does not trim, which is why all nine of EFS's
equivalent guards are reachable and covered. Two routers in one tree answering differently on the same
input class is the part worth fixing, and it is filed as #1009 rather than settled here: whether AWS
answers a validation error, a 404 or the collection operation for a trailing slash is unverified, and
MSK is the weakest service in the tree to settle that from documentation, for the reasons above.

Contorting a test to reach dead code would have bought a coverage number and no assurance.

Provenance

  • Published per operation: Kinesis InvalidArgumentException (all sixteen), Lambda
    InvalidParameterValueException (all four), EFS BadRequest (all four, "Returned if the request is
    malformed or contains an error such as an invalid parameter value or a missing required parameter"
    ),
    Service Quotas IllegalArgumentException (all four, "Invalid input was provided."), Budgets
    InvalidParameterException (all five), SES v2 BadRequestException (all five), Batch
    ClientException, Bedrock Runtime ValidationException (both, unchanged).
  • Published on a common-errors page: ValidationError/400 for EventBridge, SageMaker, ACM,
    Firehose and Cost Explorer. Step Functions', Systems Manager's and KMS's pages are byte-identical
    — fifteen entries, same order, same statuses — and the same entry with the same gloss appears on the
    other five, which is what makes a finding at one service transfer rather than a coincidence to
    re-derive.
  • Substrate's reading, stated as such: MSK's BadRequest, because nothing is published to check it
    against; CloudWatch's SerializationException, unchanged.
  • A trap worth naming: an error named in prose is not an error a shape publishes. Five Systems
    Manager pages name ValidationException in prose and none lists it in an Errors section; four Step
    Functions pages do the same.

Compatibility

Every affected operation answered HTTP 400 before this change and answers 400 after, so a caller
branching on the status sees nothing new. A caller matching on the code string for a malformed body
sees a different one at eighty-three sites — the twelve services and their old and new codes are
tabulated in docs/services.md under "A request body that will not parse", alongside the fourteen
services audited and found already correct so they are not re-derived. A caller parsing the message
no longer receives encoding/json's text at twenty-two of them.

MSK, CloudWatch and Bedrock Runtime keep their codes; only their messages, and one conflated guard,
change.

Verification

The nine-command gate, all green: gofmt, go build, go vet, golangci-lint run ./... (0 issues),
make test, GOTOOLCHAIN=go1.26.6 make test, GOTOOLCHAIN=go1.26.6 make coverage,
make docs-reference docs-reference-check docs-versions authz-reference-check,
npm --prefix docs run build, and the e2e suite. Coverage 84.9% emulator / 84.4% total, up from
the 84.7% / 84.2% baseline.

Every changed line is covered except the five unreachable guards above, verified by cross-referencing
git diff main...HEAD --unified=0 against the coverage profile rather than by reading the percentage.

Both tables were mutation-checked, because a large table that passes on the first run is otherwise
indistinguishable from one that passes vacuously. Flipping one expected code in the parse-guard table
produces 11 failures; flipping the MSK empty-ARN message, the EFS prefix message and the Service Quotas
code in the member table produces 4, 4 and 3. All 43 member subtests are confirmed to run rather than
skip.

The count correction to this issue's earlier plan comment is on the record at
#950 (comment) — the verified figures are
110 code corrections across fourteen services and 22 message fixes, not the 50 and 17 posted
there.

…ode (#950)

Eighty-three more sites in twelve services answered an error code their own
operation does not publish, and twenty-two of them handed the caller
encoding/json's error text as the message.

The rule applied uniformly: prefer a per-operation code where one is published
in the Errors section of every guarded site, and fall back to the service's
common-errors page only where none is. Step 1 settled Kinesis, Lambda, EFS,
Service Quotas, Budgets, SES v2 and Batch; step 2 settled EventBridge,
SageMaker, ACM, Firehose and Cost Explorer.

MSK kept BadRequest, recorded as substrate's reading: it publishes no
common-errors page, its operation pages carry no Errors section, and
CreateClusterV2 has no documentation page at all.

CloudWatch's CBOR arm still appends its decoder's message, deliberately —
cborDecode's text is substrate's own and describes the wire, where
encoding/json's describes Go.

Five sites conflated a parse failure with a missing member and are split.

invalid_body_inventory_test.go sends bytes at all 66 guarded operations,
asserting the status and the code together per #923.
@scttfrdmn scttfrdmn added this to the v0.118.0 milestone Sep 17, 2026
…t settled (#1006)

The paragraph #950 added asserted that checking a function exists before
parsing the body is the correct precedence. That is a design argument, not
something AWS publishes: no Lambda page states it, and the Errors sections
list ResourceNotFoundException and InvalidParameterValueException without
ordering them. A REST-JSON frontend that deserializes before dispatch would
answer 400 instead.

Recorded as unverified and filed as #1006, where the real question is whether
the answer generalises to every operation that reads state above its guard.
@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.48744% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/msk_plugin.go 72.72% 3 Missing ⚠️
emulator/sesv2_plugin.go 50.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

The 40 changed lines codecov/patch reported uncovered are the sites whose
code #950 corrected that are not parse guards -- the "+ N member" column of
the docs/services.md inventory. Leaving them unverified would undercut this
PR's own thesis, so 35 of them now have a wire test.

They send "{}" rather than a truncated body, because "{}" parses and so
travels past the parse guard to the member check underneath, where an
unparseable body stops one line earlier. Each asserts the message alongside
the code: once every site in a service answers one code, the message is the
only thing distinguishing them.

Five cannot be reached by any request and are recorded rather than tested.
parseKafkaOperation and parseSESv2Operation both trim a trailing slash, so a
request naming an empty path parameter collapses onto the collection route --
GET /v1/clusters/ dispatches ListClusters, not DescribeCluster with an empty
ARN -- making MSK's describeCluster, deleteCluster and describeClusterV2
checks and SES v2's getEmailIdentity and deleteEmailIdentity checks dead
code. Each now says so at the line a reader would look. MSK's
getBootstrapBrokers and listNodes escape because a literal segment follows
the ARN; parseEFSOperation does not trim, which is why all nine of EFS's
equivalent guards are reachable. Filed as #1009.

Coverage 84.9% emulator / 84.4% total, from 84.8 / 84.3.
@scttfrdmn
scttfrdmn merged commit ba15d84 into main Sep 17, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/parse-guard-codes-inventory-950 branch September 17, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Twenty-seven plugins answer twenty-one different codes for an unparseable body, and at least three are codes the service does not publish

1 participant