Repository navigation
Description
Context
Found while wiring calque (a Go CLI at github.com/spore-host/calque) to use
Substrate as an offline test harness for its EC2 acquisition code
(internal/plan/acquire.go's Acquirer, wrapping spawn's
*spawnaws.Client/launcher.Provision).
Repro
Seed a fault rule and call RunInstances via a real AWS SDK v2 EC2 client
pointed at a Substrate TestServer:
ts := emulator.StartTestServer(t)
// POST /v1/fault/rules: {"enabled":true,"rules":[{"service":"ec2","operation":"RunInstances","fault_type":"error","error_code":"InsufficientInstanceCapacity","http_status":500,"probability":1.0,"times":-1}]}
cfg, _ := config.LoadDefaultConfig(ctx,
config.WithBaseEndpoint(ts.URL),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("test", "test", "")),
)
client := ec2.NewFromConfig(cfg)
_, err := client.RunInstances(ctx, &ec2.RunInstancesInput{...})A raw HTTP POST to the same endpoint (bypassing the SDK) confirms Substrate
sends:
<ErrorResponse><Error><Type>Sender</Type><Code>InsufficientInstanceCapacity</Code><Message>injected fault</Message></Error></ErrorResponse>The mismatch
The AWS SDK v2 EC2 client uses the ec2query protocol for error
deserialization. Its GetErrorResponseComponents
(aws-sdk-go-v2/aws/protocol/ec2query/error_utils.go) declares:
type ErrorComponents struct {
Code string `xml:"Errors>Error>Code"`
Message string `xml:"Errors>Error>Message"`
RequestID string `xml:"RequestID"`
}Note the XPath: Errors>Error>Code — a plural <Errors> wrapping
element. Substrate's response has <ErrorResponse><Error><Code> — no
<Errors> wrapper at all (it looks like the REST-XML / query-protocol
success-response shape, or possibly modeled after S3/IAM's error shape
rather than EC2's specifically).
Because the XPath doesn't match, Code decodes as "", and the SDK's
error handling falls back to a generic smithy.GenericAPIError with code
"UnknownError" — the real injected code (or a real EC2 error code on a
genuine AWS-side failure) never reaches the caller.
Impact
Any consumer using the real AWS SDK v2 EC2 client against Substrate
(not just fault-injection scenarios — this would affect ANY EC2 error
response Substrate returns, including organically-triggered ones from
state/quota/consistency checks) cannot classify EC2 errors by their real
AWS error code. For calque specifically, this means our
Acquirer.classify()'s capacity-vs-terminal-vs-unknown error taxonomy
(keyed on codes like InsufficientInstanceCapacity,
InvalidAMIID.NotFound, etc.) can't be exercised end-to-end against
Substrate — it always sees UnknownError instead of the real code.
Suggested fix
Confirmed against a real AWS EC2 RunInstances error response — EC2's
actual wire format DOES use the <Errors><Error>...</Errors> wrapper
(this is standard EC2 Query-protocol error shape, distinct from S3/other
REST-XML services' unwrapped <Error>). writeError
(emulator/server.go) should emit the EC2/query-protocol shape
specifically for EC2 (and any other Query-protocol service Substrate
emulates), rather than the current one-size-fits-all
<ErrorResponse><Error> shape that seems to target REST-XML services.
Files referenced
emulator/server.go'swriteError(the response-writing code)emulator/fault.go/emulator/fault_control.go(where I found this,
via fault injection, but it's not specific to faults — any EC2 error
path hits the samewriteError)
Version
Found against github.com/scttfrdmn/substrate v0.94.0 (via go get),
though the same code appears present in the local dev checkout too.
Activity
feat(plan): adopt Substrate as the offline AWS test tier (calque#114)
scttfrdmn commentedon Aug 8, 2026
Confirmed on
main(9c5f6e8, latest tagv0.94.0). Two findings go beyond what the issue tests, and one of them changes the scope of the fix.1. It is not fault-specific — organic errors are broken identically. The issue notes this as a likelihood but only exercises the injected fault. Verified with the real SDK (
service/[email protected]) against a live server:DescribeInstancesoni-0000000000000deadreturns the same<ErrorResponse><Error>wrapper carryingInvalidInstanceID.NotFound, and the SDK reportscode="UnknownError" msg="UnknownError"— exactly as the injectedInsufficientInstanceCapacitydoes. That is becausewriteError(emulator/server.go:722) delegates the shape entirely tomarshalAWSError, and all 8 of its call sites — parse, signature, presigned expiry, auth, quota, consistency, fault, and the plugin route — go through it. So the fix belongs in the serializer, and it covers both paths at once.2. botocore tolerates both shapes, which is why every AWS-CLI gate here passed.
EC2QueryParser._get_error_rootwalks the root's children for anErrorselement and returnsoriginal_rootwhen it is absent, so the wrong document and the documented one both parse to the right code. Measured:aws ec2 describe-instances --instance-ids i-0000000000000deadreportsInvalidInstanceID.NotFoundcorrectly today, against the broken shape. Substrate's EC2 coverage is CLI-driven, so no existing test could have caught this — only a real-SDK test can, and the fix is CLI-safe by the same token.Pre-verified, not inferred. A stand-in server serving the AWS-documented shape —
— made the same SDK probe report
code="InsufficientInstanceCapacity" msg="injected fault"for both the injected and the organic call.Scope.
ec2is the only service on theec2protocol (checked theprotocolfield of every botocore service model), and the two documents are mutually exclusive:ec2query.ErrorComponentsreadsCodeat the XPathErrors>Error>Codewhile the sharedawsxml.wrappedErrorResponsereadsError>Code, and each yields""for the other's document. So this is one newawsErrorProtocolarm plus one moved map entry — following the structure #480 established for S3 — not a change to the shared Query shape, which IAM and every other query service still need. CFN's in-process stack deploys are unaffected:cfnDispatchErrorreads the code withextractXMLField(resp.Body, "Code"), a substring scan at any depth rather than a struct decode.One correction to make along the way: the
serviceErrorProtocolsdoc comment currently asserts that "every one of their parsers recovers the code from an<ErrorResponse><Error><Code>document, so a single shape serves all three". This issue is that sentence being false for theec2protocol.Milestoned to v0.95.0.
fix(ec2): serialize errors in the ec2 protocol's own document (#591) (#…