Repository navigation
Description
What
Forty-nine write sites across twenty-two non-test files discard the error from
StateManager.Put, so a request whose store failed answers 200 and reports the change it did
not make.
The idiom is uniform:
newData, _ := json.Marshal(inst)
_ = p.state.Put(context.Background(), ec2Namespace, key, newData)emulator/ec2_plugin.go:1392-1393, inside stopInstances. The handler then builds a
stateChange reporting previousState: running → currentState: stopping and answers
200. If the Put failed, the instance is still running in the store, and the caller has
been told in the published response shape that it is not.
StateManager.Put is declared fallible — emulator/types.go:187:
// Put stores value at namespace/key, creating or overwriting as needed.
Put(ctx context.Context, namespace, key string, value []byte) errorThe reason this has stayed invisible is that the only implementation in the tree cannot
fail. MemoryStateManager.Put (emulator/state.go:81-94) takes a mutex, copies the value
into a map and returns nil on every path. But StateManager is an exported interface, so a
consumer embedding substrate can supply a store that does fail — and the tree already contains
one that does, for exactly this purpose (below).
This is the shape #639 already fixed, in one service
TagUser used to answer 200 and store nothing. #639 fixed it, and the fix came with a
fault-injecting store and a regression test that are both still in the tree:
iamFailingPutStateManager(emulator/iam_tagging_test.go:576-599) wraps a
MemoryStateManagerand returns a seeded error fromPutwhen armed.TestIAMTagging_AFailedWriteIsReportedRatherThanSwallowed
(emulator/iam_tagging_test.go:626-653) arms it against six tagging operations and asserts
http.StatusInternalServerError. Its comment states the rule in the terms this issue is
about: "a tag operation whose read succeeded and whose store failed must not answer 200. A
consumer that got a success and no tags would have no way to tell the difference from AWS
accepting the call, which is the failure mode IAM query-protocol list parameters never reach a handler, so TagUser/UntagUser/TagRole/UntagRole silently discard what an SDK sends #639 was."
iam_plugin.go wraps its writes accordingly at :295, :530, :623, :806, :1350,
:1585, :2066, :2333 and elsewhere. So both the handling pattern and the test harness for
proving it exist; forty-nine sites simply predate or missed them.
CLAUDE.md also forbids the idiom outright: "Errors: never discard; wrap with context using
fmt.Errorf("…: %w", err)."
Where the forty-nine are
| File | Sites |
|---|---|
ec2_plugin.go |
13 |
elb_plugin.go |
6 |
opensearch_plugin.go |
5 |
testing.go |
3 |
ssm_plugin.go, rds_plugin.go, lambda_plugin.go, efs_plugin.go |
2 each |
timestream_plugin.go, sqs_plugin.go, s3_plugin.go, route53_plugin.go, lambda_exec.go, elasticache_plugin.go, ecr_plugin.go, dynamodb_plugin.go, cognito_idp_plugin.go, cloudwatchlogs_plugin.go, cloudwatch_plugin.go, cloudfront_plugin.go, cfn_resources_v32.go, cfn_deployer.go |
1 each |
Every one of the thirteen EC2 sites is a mutation a consumer asserts on: stopInstances
(:1393), startInstances (:1447), modifySGRules (:2173), attachInternetGateway
(:2355), detachInternetGateway (:2387), associateRouteTable (:2597),
disassociateRouteTable (:2633), createRoute (:2663), replaceRoute (:2714),
deleteRoute (:2866), associateAddress (:5460), disassociateAddress (:5508, :5517).
The six ELB sites are modifyTargetGroup (:439), registerTargets (:489),
deregisterTargets (:531), modifyListener (:744), setRulePriorities (:946) and
removeFromList (:1122). removeFromList is the one that needs a signature change rather
than an if: it is declared func (p *ELBPlugin) removeFromList(scope, listName, id string)
with no return value, so it structurally cannot report a failure to its caller.
Why this matters
A discarded Put is the worst-shaped failure an emulator can have, because it inverts the
property substrate exists to provide. Everywhere else, a wrong answer is at least a consistent
wrong answer that a test can pin. Here the response describes a state transition and the store
does not contain it, so the very next Describe call contradicts the call that just succeeded —
and the event log records both, which means a replay reproduces the contradiction faithfully and
a reader cannot tell whether they are looking at an emulator bug or the consumer's.
It also matters for the embedding case specifically, which is the only case where it can fire
today. A consumer who supplies a persistent or instrumented StateManager — the reason the
interface is exported — inherits forty-nine silent-write-loss sites, and the symptom they see is
"substrate loses my resources intermittently" with nothing in the response or the event log
pointing at the store.
The fix is mechanical at forty-eight of the forty-nine sites and the shape is already written
eight times over in iam_plugin.go. What makes this an issue rather than a sweep PR is the
status question, removeFromList's signature, and the three sites in testing.go, which is a
helper file in the non-test package and may want a different rule.
Acceptance criteria
- Every
_ = <x>.state.Put(...)in a non-test file is replaced by a wrapped return, in the
fmt.Errorf("<service> <handler>: %w", err)formiam_plugin.goalready uses. -
ELBPlugin.removeFromListreturns anerrorand every caller propagates it. If a caller
cannot propagate, say which and why in the function's doc comment rather than restoring the
discard. - The three
testing.gosites are decided explicitly — wrapped, or documented as deliberate
with the reason, since a helper that cannot fail in practice is a different case from a
request handler. Do not leave them as bare discards either way. - The status a store failure reports is stated once and applied uniformly. IAM answers
500; whether that is the answer for the Query-protocol and REST-JSON services here
depends on what each service's own Common Error Types list publishes, so read that list per
protocol and record the reading rather than assuming IAM's answer generalises (ec2: an invalid block device mapping is accepted instead of refused with InvalidBlockDeviceMapping #671). - A fault-injecting store proves it, following
iamFailingPutStateManager's shape. Promote
that fixture out ofiam_tagging_test.goso it can be shared rather than copied per
service — the copy-per-service alternative is what will make this sweep rot. - At least one test per file touched arms the failing store against a mutation and asserts
the request does not answer200, following
TestIAMTagging_AFailedWriteIsReportedRatherThanSwallowed. - A
maketarget or an added case in the existing discarded-error check
(scripts/check-discarded-unmarshal.sh, wired atMakefile:65) fails the build on a new
_ = <x>.state.Put(so the count cannot grow back. This is the criterion that makes the
rest durable. - No behavioural change on the success path: with
MemoryStateManager, every existing test
and every recorded event log replays byte-identically, sincePutnever returns an error
there.
Out of scope, recorded so the class is not re-discovered
Three sibling discard families exist and are not in this issue, because each has a different
consequence and a different fix:
- 67 discarded
state.Get(, _ := <x>.state.Get() — conflates a store failure with the
key being absent, so a read failure is reported as a missing resource. codebuild: batchGetBuilds reports a read failure as a build that does not exist, and ids is unchecked #1186 is the one filed
instance (CodeBuildbatchGetBuilds);ec2_plugin.go:5236indeletePlacementGroupis
another. - 42 discarded
state.Delete— a delete that did not happen answers success. - 150 discarded
json.Marshal— cannot fail for any struct in the tree (no channel, func or
cyclic members), so this is a house-rule violation with no reachable consequence. Worth a
separate, low-priority sweep, and worth not bundling here, because mixing it in would make a
correctness fix look like a lint pass.
Provenance
This is not a divergence from a published AWS shape; it is a correctness and house-rule defect,
and the provenance is in-tree:
emulator/types.go:187declaresPutfallible;emulator/state.go:81-94is the only
implementation and always returnsnil, which is why no test catches it today.- IAM query-protocol list parameters never reach a handler, so TagUser/UntagUser/TagRole/UntagRole silently discard what an SDK sends #639 is the same defect in IAM, already fixed, with
iamFailingPutStateManager
(emulator/iam_tagging_test.go:576) and
TestIAMTagging_AFailedWriteIsReportedRatherThanSwallowed(:626) as the fixture and the
regression test, andiam_plugin.go's eight wrapped writes as the handling pattern. CLAUDE.md, Code conventions: "Errors: never discard; wrap with context using
fmt.Errorf("…: %w", err)."
The counts (49 / 22 files, and the per-file table) are from the tree at the commit this issue was
filed against.
Activity
chore(release): v0.124.0 (#1415)