Repository navigation
fix(ec2): serialize errors in the ec2 protocol's own document (#591) - #592
Merged
Merged
Conversation
EC2 is the only service on the "ec2" protocol, whose error document wraps the error in a plural <Errors> element and spells the request id <RequestID> with a capital D. Substrate served the Query protocol's <ErrorResponse><Error>, so aws-sdk-go-v2's ec2query deserializer — which reads the code at the XPath Errors>Error>Code — recovered an empty string and fell back to UnknownError. Organic errors were affected as much as injected faults: both share writeError's single serializer, so DescribeInstances on an absent instance ID arrived as UnknownError too. The issue reported the fault and predicted the rest. EC2 gets its own error-protocol arm, alongside the one S3 got for the same class of bug in #480, and it is the sole member. The two documents are mutually exclusive — the Query parser reads Error>Code where the EC2 parser reads Errors>Error>Code — so this could not be a shared shape. The regression gate is a real-SDK one. botocore is lenient where the SDKs are strict: its EC2 parser falls back to the document root when <Errors> is absent, so the AWS CLI read the correct code out of the wrong document and every CLI-driven test passed. test/e2e now depends on aws-sdk-go-v2/service/ec2 to host that gate.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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 #591
EC2 is not on the AWS Query protocol. It is the only service on the
ec2protocol, whose error document wraps the error in a plural<Errors>element and spells the request id<RequestID>with a capital D. Substrate served the Query shape, so AWS SDK v2'sec2querydeserializer — which reads the code at the XPathErrors>Error>Code— recovered an empty string and fell back tosmithy.GenericAPIError{Code: "UnknownError"}. A consumer branching onInsufficientInstanceCapacityorInvalidInstanceID.NotFoundnever saw either code, so every EC2 retry/wait loop written against the SDK was untestable.Organic errors were broken too, not just faults
The issue reported a seeded capacity fault and predicted the rest; this confirms it.
writeErrorhas 8 call sites — parse, signature, presigned expiry, auth, quota, consistency, fault, and the plugin route — and all of them delegate the shape to onemarshalAWSErrorcall, soDescribeInstanceson an absent instance ID arrived asUnknownErrorexactly as the injected fault did. Both are fixed by the single arm; noserver.gochange was needed.Why an arm and not a wider default
The two documents are mutually exclusive: the Query parser reads
Error>Codewhere the EC2 parser readsErrors>Error>Code, and each recovers""from the other's document (asserted inTestEC2Error_IsNotTheQueryDocument). So EC2 needed its own arm — following the structure #480 established for S3 — and IAM, CloudFormation and every other XML service keep the wrapper they had.ec2is the sole member of the new arm, checked against theprotocolfield of every botocore service model.The
<RequestID>is the fixed stringSUBSTRATE, matching S3's document rather thangenerateRequestID(), which derives fromtime.Now().UnixNano()and would make an error body differ between two replays of one recorded run. That literal became a sharedsubstrateRequestIDconstant so the reasoning lives in one place.Why substrate's own coverage missed this
botocore is lenient where the SDKs are strict.
EC2QueryParser._get_error_rootwalks the root's children forErrorsand returnsoriginal_rootwhen it is absent, so the AWS CLI read the correct code out of the wrong document the entire time — verified live,aws ec2 describe-instancesreportedInvalidInstanceID.NotFoundeven before this change. Every CLI-driven EC2 test passed, and no unit test asserting bytes would have flagged the shape as wrong without knowing the SDK's XPath.So the regression gate is a real-SDK one:
test/e2e/journey_ec2_errors_test.goassertssmithy.APIError.ErrorCode()for both the organic and the injected case, andtest/e2enow depends onaws-sdk-go-v2/service/ec2to host it. Reverting the one map entry makes it fail withErrorCode() = "UnknownError", which is #591 verbatim.Two existing tests encoded the false premise in their names and moved rather than being weakened:
TestQueryXMLError_UsesErrorDocument(the #392 gate, which used EC2 as its vehicle for the generic Query shape) andTestFault_OtherProtocolsAreUnchanged's"ec2 stays query xml"subtest. Both now use CloudFormation, which is genuinely Query, and EC2 got its own subtest. Loosening either to accept both shapes would have retired the gate instead of moving it.Verification
gofmt -l .clean,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issues;make test(race) green in both modules. The 4 lint findings intest/e2e/e2e_test.goare pre-existing and untouched; the new file is clean.ec2ErrorCode,ec2ErrorDetail,ec2ErrorCodeOf), which puts the existing EC2 suite behind the shape: reverting the map entry fails 159 unit assertions plus the e2e gate. The third helper was found by the suite, not by grep — it omits theXMLNamefield.substrate server: EC2 returns<Response><Errors><Error><Code>…with<RequestID>SUBSTRATE</RequestID>on both the organic and injected paths; IAM and CloudFormation still return<ErrorResponse><Error><Type>Sender</Type>…; the AWS CLI reads both the organic and the injected code correctly (no regression); a CFN stack holding anAWS::EC2::VPCstill reachesCREATE_COMPLETE, sincecfnDispatchErrorreads the code withextractXMLField— a substring scan at any depth, not a struct decode.ec2reverted to the Query arm (159 unit + e2e); the<Errors>wrapper dropped (159 unit + e2e);<RequestID>respelled<RequestId>(unit only — the SDK does not need the request id to recover the code, which is why that spelling got its own explicit assertion); the arm applied beyondec2(the CFN suite goes red, proving the carve-out is scoped); andRequestIDswitched togenerateRequestID()(the determinism gate).Provenance
The document shape is quoted from the EC2 error reference; the XPaths come from
aws-sdk-go-v2/aws/protocol/ec2query/error_utils.go.RequestID: "SUBSTRATE"is substrate's own choice for replay determinism, not a value AWS sends.Compatibility
Any test decoding an EC2 error as
<ErrorResponse><Error>must switch to<Response><Errors><Error>. The AWS CLI and the SDKs are unaffected in the sense that neither breaks — but an SDK caller now gets a correct code where it previously gotUnknownError, so an error-matching branch that silently never fired may start firing.