Repository navigation
feat(protocol): shape errors by the request's protocol (#757, #758) - #790
Merged
Merged
Conversation
Record the wire protocol a caller used on AWSRequest and let the error serializer follow it, for the one service whose model declares several. CloudWatch carries awsQuery, awsJson1_0, rpcv2Cbor and awsQueryCompatible on one service shape, and its clients disagree about which to send. Before this change a refused SetAlarmState reached aws-sdk-go-v2 as "deserialization failed, unexpected minor value 28" and the AWS CLI as "An error occurred (400)"; both now report InvalidParameterValue, and the Go SDK deserializes the modeled InvalidParameterValueException. Which services may be reclassified by their caller is an enumerated set of one, not a Content-Type sniff — deciding by Content-Type is what #392 removed, and letting the request speak for a single-protocol service would reclassify Lambda's REST-JSON errors as Query. cloudwatch_errors.go holds CloudWatch's 17 error shapes read off the AWS-published Smithy model: Query code to shape ID, fault, status, and the casing of the message member, which the model spells Message on some shapes and message on others. X-Amzn-Query-Mode is honored with an x-amzn-query-error response header. A request declaring rpc-v2-cbor and a target header is refused with a shaped SerializationException. sso is JSON 1.1, not REST-JSON: the plugin emulates sso-admin, and both its error shape and its success Content-Type followed from reading it as the unrelated sso service. Closes #758
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
5 tasks
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.
Second of four PRs for v0.110.0. Records the wire protocol a caller used and shapes errors to follow it, closing the error half of #757 and all of #758. CloudWatch's successful responses are still XML on every protocol — that is #785, the next PR.
Closes #758The problem, measured
CloudWatch's service shape carries
aws.protocols#awsQuery,aws.protocols#awsJson1_0,smithy.protocols#rpcv2Cborandaws.protocols#awsQueryCompatibleat once, and its clients disagree about which to use. Substrate classified error protocol per service, so one answer went to all three. Measured against amainbuild, a refusedSetAlarmState:aws-sdk-go-v2v1.47.0 / cloudwatch v1.72.0deserialization failed, unexpected minor value 28— not anAPIErrorat allInvalidParameterValue: AlarmName is required, deserialized intotypes.InvalidParameterValueExceptionAn error occurred (400)— the stringified status, with the XML leaking into the messagebotocore.errorfactory.InvalidParameterValueException, codeInvalidParameterValueunexpected minor value 28is the<of<ErrorResponse>(0x3C — major 1, additional info 28, which is reserved) being read as a CBOR head.What changed
emulator/protocol.go(new) — exportedWireProtocol(WireQueryas the zero value,WireJSONRPC,WireRPCV2CBOR) and a pure, totaldetectWireProtocol. Signals in the order a conformant client makes them available: the requiredSmithy-Protocol: rpc-v2-cborheader, then a/service/…/operation/…path with a CBOR Content-Type (a prefix before/serviceis permitted, so the tail decides), thenX-Amz-Target, thenapplication/x-amz-json. AlsodetectQueryModeandrpcV2CBORTargetConflict.emulator/types.go/parser.go—AWSRequestgains exportedProtocol WireProtocolandQueryMode bool, set during parsing so authorization, fault injection, the plugin and the error serializer all agree about what arrived. Exported so a third-party plugin can serve CBOR too. Additive:WireQueryis the zero value, so an in-processAWSRequestbuilt by hand still reads as Query.emulator/error_protocol.go—errProtoRPCV2CBOR, anerrorWireContextcarrying the protocol/service/query-mode the two newer arms need, anderrorProtocolForRequest. The set of services the request may reclassify is enumerated, one member:Deciding by Content-Type is exactly what #392 removed — a REST-JSON service sends a bare
application/json, indistinguishable from a plain JSON body — so letting the request speak for a single-protocol service would reclassify Lambda's errors as Query and undo that fix.TestErrorProtocolForRequestpins the asymmetry in both directions (lambda,s3,ec2,iamare not reclassified by a CBOR or JSON-target header).emulator/cloudwatch_errors.go(new) — CloudWatch's 17 error shapes, each read offcodegen/sdk-codegen/aws-models/cloudwatch.jsoninaws-sdk-go-v2. The Query code (aws.protocols#awsQueryError.code) maps to the shape ID, the fault (smithy.api#error), the status (smithy.api#httpError) and the casing of the message member, which the model spellsMessageonInternalServiceFaultandmessageonInvalidParameterValueException. A CBOR client deserializes by exact member name, so guessing loses the message.An unmodeled code passes through unqualified. That covers every code the pipeline itself raises —
AccessDenied,InternalFailure,InvalidAction,InvalidClientTokenId,ThrottlingException,UnknownOperationException— and is safe because a reference client sanitizes__typeby taking the text after#, so an unqualified value yields the same discriminant a qualified one would.The query-compatibility bridge.
X-Amzn-Query-Mode: truewas read nowhere; it now producesx-amzn-query-error: <Code>;Sender|Receiveron both the CBOR and the JSON-RPC arm (awsQueryCompatibleapplies toawsJson1_0too). With both halves in place the CLI raises the typed exception from__typeand displays the Query code from the header, which is exactly the split the trait exists to bridge.The malformed combination is refused. A request declaring
Smithy-Protocol: rpc-v2-cborand carrying a target header gets a shaped 400 rather thanhttp.Error's plain text. Substrate routes onX-Amz-Targetbefore anything else, so honoring it would mean invoking whatever the target named while answering in the serialization the path asked for. The spec mandates the rejection without naming a code; substrate answersSerializationExceptionand the doc comment says that this is substrate's choice.monitoringleavesserver.go's query→JSON body reconstruction. It was already a no-op (a CBOR request has no form body, soreq.Paramsis empty and the guard never fires) but it said the opposite of what #785 needs.#758 —
ssois JSON RPC, not REST-JSON. The plugin emulatessso-admin: it dispatches onX-Amz-Targetwith theSWBExternalServiceprefix, andsso-admin's model is"protocol": "json","jsonVersion": "1.1". Both consequences of reading it as the unrelatedssoservice are fixed — errors move from anx-amzn-errortypeheader botocore's JSON parser never reads to the body's__type, and successes move fromapplication/jsontoapplication/x-amz-json-1.1. No test asserted either value, which is how both survived #561's routing fix.Provenance
aws-sdk-go-v2, not the CloudWatch API reference, which documents only the Query codes (InvalidParameterValue, neverInvalidParameterValueException) and nothing about member casing.queryError.httpResponseCodeequalshttpErrorfor every CloudWatch shape, so there is no status divergence to reconcile. The plan assumed there might be; there is not. (The protocol test suite does construct one, but only in a synthetic service.)X-Amzn-Query-Mode/x-amzn-query-errorare normative but appear in neither the rpcv2Cbor spec page nor theawsQueryCompatibletrait docs — only insmithy-aws-protocol-tests/model/rpcv2Cbor/query-compatible.smithy. Both reference clients send the request header, which is the corroboration.ThrottlingExceptionis 400 for CloudWatch, not 429 (CommonErrors.html), and takes the pass-through path.SerializationExceptioncode for the malformed-request refusal is substrate's choice; the spec mandates the rejection and names no code.Compatibility
__type, and a raw Query client is byte-identical. Verified below.ssoerror bodies change from REST-JSON to JSON-RPC, andssosuccessContent-Typefromapplication/jsontoapplication/x-amz-json-1.1.AWSRequestgains two exported fields. Additive; a third-party plugin compiles unchanged and reads as Query without setting them.accessDeniedCodeFor("monitoring", …)staysAccessDeniedon every protocol. No query-protocol service models an access-denied shape, CloudWatch's model declares nothing to contradict the observed value, and a code that changed with the caller's serialization would be harder to assert against. The doc comment says so.Verification
Both toolchains, each command's exit code read separately:
Live proof,
substrate server --address :4678, before-binary built from a detached worktree atmain:Also verified live: the
rpc-v2-cbor+X-Amz-Targetcombination answers a CBORSerializationException400 withSmithy-Protocolechoed;ssoerrors answerapplication/x-amz-json-1.1with__typein the body;ssosuccesses answer the versioned Content-Type; and a CloudWatch QueryListMetricsis unchanged.Tests
emulator/protocol_test.go— 13 classification cases built from the requests the three real clients actually send (captured from a running emulator, not invented), plus the nil-request totality property, the zero-value property, query-mode parsing, the target-conflict check on both header spellings, and end-to-end assertions thatParseAWSRequestrecords both fields.emulator/cloudwatch_errors_test.go— all 17 shapes with their four model facts restated, a closed-table assertion so a row added without a model behind it fails, the fallback for all seven pipeline codes, the #392 non-reclassification guard, and the CBOR/JSON error documents including the members that must not be present.Part of #785 / milestone v0.110.0. Next: PR 3/4 makes CloudWatch's success responses follow the protocol too.