fix(iaas): return after a failing GetServer in the server resource - #1747
Open
devpie wants to merge 1 commit into
Open
fix(iaas): return after a failing GetServer in the server resource#1747devpie wants to merge 1 commit into
devpie wants to merge 1 commit into
Conversation
Both the create and the update path called GetServer, logged the error with core.LogAndAddError and then carried on with a server that is nil on that path. In Update the consequence is a crash: nothing guards the value between the failing call and `server.Status`, so any failing GetServer - a 500, a timeout, a transient network error - panics the provider process instead of reporting the diagnostic that was just recorded. In Create the same omission is caught by accident, because mapFields rejects a nil response and the caller returns on that error. The diagnostic then names "Processing API payload" rather than the call that actually failed, and the guard is one refactor away from being gone. NilAway reports resource.go:840 on main and no longer reports it with this change. The create path is covered by a test that fails without the fix; the update path is not, because reaching Update through the test framework needs a complete server fixture to round-trip first. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Description
relates to #1746
Both the create and the update path of
stackit_servercalledGetServer, logged the error withcore.LogAndAddErrorand then carried on with aserverthat is nil on that path.In
Updatethe consequence is a crash: nothing guards the value between the failing call at:825and
server.Statusat:840, so any failingGetServer— a 500, a timeout, a transient networkerror — panics the provider process instead of reporting the diagnostic that was just recorded.
In
Createthe same omission is caught by accident, becausemapFieldsrejects a nil response andthe caller returns on that error. The visible effect there is a misleading diagnostic
(
Processing API payload: response input is nilinstead of the call that actually failed), and theguard is one refactor away from being gone.
The change is two
returnstatements.Evidence
NilAway reports
resource.go:840onmainand does notreport it with this change applied. The two remaining findings in that file
(
resource.go:552,:775) are a different class — the one described in #1743 — and are out ofscope here.
The create path is covered by
TestCreateReportsFailingGetServerDetails, which fails without thefix.
ExpectErrorcannot express this assertion, because the apply fails either way; the test usesErrorCheckto assert that the second, wrong diagnostic is absent.The update path is not covered by a unit test: reaching
Updatethrough terraform-plugin-testingneeds a complete server fixture to round-trip through the mock first. Happy to add it if you would
rather have it.
Checklist
make fmtexamples/directory) — not applicable, no configuration surface changesmake generate-docs(will be checked by CI) — no schema changeGetServercannot be provoked against the real APImake test(will be checked by CI)make lint(will be checked by CI)🤖 Generated with Claude Code