Repository navigation
chore(cfn): classify StackDeployer failures with sentinels, not substrings (#502) - #536
Merged
Merged
Conversation
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.
cfnMapDeployerErrorrecovered a CloudFormation error code and HTTP status byrunning
strings.Containsover the deployer's message. That worked, and it coupledtwo things that have no business being coupled.
It was fragile in both directions. Rewording
stack %q not found— an ordinarycopy-edit — silently turned a
ValidationErrorat 400 into anInternalFailureat500 for every consumer, with no compiler error and no failing test outside the
plugin's own suite. And it was lossy the other way:
deploy resource %s: %wwrapswhatever the plugin returned, and a plugin's own message may well contain
"not found" — an instance whose AMI does not resolve, say — so a genuine
resource-level failure was reported as though the request had named an absent
stack, at 400 rather than 500.
What changed
StackDeployerwraps one of six sentinels —ErrCFNStackNotFound,ErrCFNChangeSetNotFound,ErrCFNDriftDetectionNotFound,ErrCFNTemplateInvalid,ErrCFNResourceDeployFailed,ErrCFNStateRequired— and the plugin classifies witherrors.Is. Nostrings.Containsremains.Every message is unchanged byte for byte. That is what makes this safe to land
on its own: anything reading a substrate log sees exactly what it saw before, and
only the classification is new. The classification is held in a field on
cfnClassifiedErrorrather than wrapped into the text with a second%w,precisely so text and code stay independent — wrapping the sentinel into the
message would have satisfied
errors.Isand changed the text every consumer's logsalready carry, which is the coupling the issue is about, reintroduced from the other
end.
A failed resource additionally carries its logical ID on a typed
CFNResourceDeployError.DescribeStackResourcesreads a failure off the resourcerecord rather than off this error (#519), but a deploy that fails outright returns
before any record is written, so the logical ID has to travel with the error or it
is lost.
Why now
The v0.88.0 plan parked #502 with a stated trigger: it joins the release if
#522 surfaces its new failures through
Deploy/DeleteStack's error return ratherthan on a resource. #522's remaining half is
Fn::ImportValue, whose delete-refusal("you can't delete the stack that is exporting the output value") has no resource to
blame and so must come back through
DeleteStack. The trigger fired, so this landsfirst as a pure mechanical refactor and the export work builds on typed errors
instead of widening the substring switch.
Tests
emulator/betty_cfn_errors_test.go. Two assertions carry the weight:err.Error()againstthe exact string it produced before, byte for byte.
sharing no word with the old switch's strings (
no stack named "x" exists,the body could not be decoded as JSON or YAML) and assert the code and statusstill resolve. Under the old mapping every one falls through to
InternalFailure.Plus: the parse failure's
*json.SyntaxErroris still reachable througherrors.Asunderneath the classification; a resource failure whose cause reads "not found" is
NotErrorIsa missing stack; and the deploy-resource path is provoked through areal template (a YAML mapping with a non-string key decodes fine and then cannot
be JSON-marshaled into a plugin request) rather than by building the error, so the
wrapping at the call site is asserted too.
Mutation testing
18 mutants: 18 CAUGHT, 0 SURVIVED, 0 EQUIVALENT. Anchor-count assert before
applying,
gofmt -w && go vetgate,-race.Three survived the first pass and each was a real test-design gap, closed rather
than proved equivalent:
classified-error-loses-its-causeanderrf-drops-the-cause— nothing assertedthe decoder's own error was reachable, only that the message mentioned parsing.
Closed by the
errors.As(&syntaxErr)assertion.deploy-returns-an-unclassified-error(the pre-CloudFormation: StackDeployer errors are untyped, so the wire plugin maps codes by string matching #502 untyped wrap at the deploysite) — no test reached that line from a template. Closed by
TestCFN_ResourceDeployFailureFromATemplate.The highest-value mutant,
map-falls-back-to-substring-match, restores the exactpre-#502 switch and is caught by three tests.
Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...(0 issues,unpiped),
make test(race),make docs-reference docs-reference-check docs-versions,npm --prefix docs run build,go vet -C test/e2e ./...,go test -C test/e2e ./...— all green.Docs:
docs/services.md§CloudFormation now states the code/status a consumer getsfor each class of failure, and that it is derived from the classification rather
than the message. CHANGELOG under
## [Unreleased]→### Changed.Closes #502