Repository navigation
fix(errors): a request body that will not parse answers a published code (#950) - #1005
Merged
Merged
Conversation
…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.
…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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
6 tasks
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
section, use that code.
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
InvalidParameterExceptionon all five of itsguarded operations and Cost Explorer publishes nothing on any of its three. It is also why Firehose
loses
InvalidArgumentExceptioneven at the one site that publishes it — a missingDeliveryStreamNameis one condition, and answering it with two codes depending on which operationreceived it is the failure mode a uniform choice exists to avoid.
Firehose is also why every guarded operation was checked, not a representative one
InvalidArgumentExceptionis published forCreateDeliveryStream— the page anyone would open first —and for neither of the other two, which publish only
ResourceNotFoundExceptionandResourceInUseException. Taking the obvious replacement from the representative page would have beenwrong 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 Errorssection (
clusters.htmldocuments response codes only, and theErrorschema it names has members{message, invalidParameter}with noCodemember), andCreateClusterV2— one of the two operationscarrying a guard — has no documentation page. So the code stays, recorded in
msk_errors.goassubstrate's reading rather than presented as modelled, the same treatment CloudWatch's
SerializationExceptionalready gets. Inventing a code on no evidence would be worse than keeping onethat 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 toldwhich 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 thetop-level item" — which is useful to the caller who wrote those bytes, where
encoding/json'sdescribes Go. Only the
WireJSONRPCarm leaked; the third arm's text comes fromcwFlattenDocand issubstrate'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 inSageMaker, one in Bedrock Runtime's
CreateModelInvocationJob, whose code was already right. They aresplit, 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
jobNameis missing when their JSON is truncatedsends them to look at the wrong thing. Athena's and Secrets Manager's conflated sites are recorded in
docs/services.mdrather than changed, because there the required member is the only member thehandler 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 errorsrather 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.ValidationExceptionis not the answer either, near asthe 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
SubmitJobandDescribeJobsbypassed it to answerInvalidParameterValue, a code on none ofthe 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.Marshalproduces valid JSON by construction — and nothing in the suite handed the serverbytes, at any of the seventeen services involved. When 110 codes were corrected, exactly one existing
test failed: the Service Quotas case that had asserted
SerializationExceptiondeliberately, andwhose neighbour two functions below already documented
IllegalArgumentExceptionas "the code themodel declares for it on every Service Quotas operation".
emulator/invalid_body_inventory_test.gonow sends bytes at 66 guarded operations in fourteenservices,
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
AddPermissionandTagResourcelook up the function before theyparse, 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
GetFunctionrather 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/patchreported 40 changed lines uncovered. All 40 are the corrected sites that are notparse 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-guardtable:
{}parses, so it travels past the guard and reaches the member check underneath, whereinvalidBodyPayloadstops one line earlier. Each asserts the message alongside the code, because onceevery 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.
parseKafkaOperationandparseSESv2Operationboth open by trimming a trailing slash, so a requestnaming an empty path parameter collapses onto the collection route one case earlier in the same switch:
GET /v1/clusters/dispatchesListClusters, notDescribeClusterwith an empty ARN. That makes MSK'sdescribeCluster,deleteClusteranddescribeClusterV2checks and SES v2'sgetEmailIdentityanddeleteEmailIdentitychecks 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
getBootstrapBrokersandlistNodesescape only because a literal segment follows the ARN, sothe empty parameter is interior rather than trailing and
/v1/clusters//nodesreaches them — both arecovered by exactly those paths.
parseEFSOperationdoes not trim, which is why all nine of EFS'sequivalent 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
InvalidArgumentException(all sixteen), LambdaInvalidParameterValueException(all four), EFSBadRequest(all four, "Returned if the request ismalformed or contains an error such as an invalid parameter value or a missing required parameter"),
Service Quotas
IllegalArgumentException(all four, "Invalid input was provided."), BudgetsInvalidParameterException(all five), SES v2BadRequestException(all five), BatchClientException, Bedrock RuntimeValidationException(both, unchanged).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.
BadRequest, because nothing is published to check itagainst; CloudWatch's
SerializationException, unchanged.Manager pages name
ValidationExceptionin prose and none lists it in an Errors section; four StepFunctions 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.mdunder "A request body that will not parse", alongside the fourteenservices 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 fromthe 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=0against 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.