{"record":{"id":"0911d25b8c14c024","repo":"hashicorp/terraform","slug":"expected-on-1-response-value-got-d","errorCode":null,"errorMessage":"expected on 1 response value, got: %d","messagePattern":"expected on 1 response value, got: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/consul/client.go","lineNumber":251,"sourceCode":"\t\t\t},\n\t\t}\n\n\t\tok, resp, _, err := kv.Txn(txOps, nil)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\t// transaction was rolled back\n\t\tif !ok {\n\t\t\tvar resultErr error\n\t\t\tfor _, respError := range resp.Errors {\n\t\t\t\tresultErr = errors.Join(resultErr, errors.New(respError.What))\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"consul CAS failed with transaction errors: %w\", resultErr)\n\t\t}\n\n\t\tif len(resp.Results) != 1 {\n\t\t\t// this probably shouldn't happen\n\t\t\treturn fmt.Errorf(\"expected on 1 response value, got: %d\", len(resp.Results))\n\t\t}\n\n\t\tc.modifyIndex = resp.Results[0].ModifyIndex\n\n\t\t// We remove all the old chunks\n\t\tcleanupOldChunks()\n\n\t\treturn nil\n\t}\n\n\tif err = store(payload); err == nil {\n\t\t// The payload was small enough to be stored\n\t\treturn diags\n\t} else if !strings.Contains(err.Error(), \"too large\") {\n\t\t// We failed for some other reason, report this to the user\n\t\treturn diags.Append(err)\n\t}\n","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/backend/remote-state/consul/client.go#L233-L269","documentation":"Defensive check after a successful single-op transaction. The store() closure submits exactly one KVTxnOp, so Consul must return exactly one result. If len(resp.Results) != 1, the protocol contract is violated; the message says 'expected on 1 response value' (a typo in source for 'only'). This branch is not expected to fire in practice.","triggerScenarios":"store(payload) -> ok==true but len(resp.Results) != 1.","commonSituations":"A Consul version returning an unexpected Txn response shape; an upstream Consul API change; essentially an impossible branch. Treat any hit as a bug.","solutions":["Capture the Terraform version, Consul version, and the full Txn response and file a bug against the consul remote-state backend.","Retry the operation once; a transient Consul quirk is the only realistic non-bug cause.","Check Consul health (`consul info`) for unusual signs."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// This branch is defensive; treat as a bug and retry once, then surface clearly.\ndiags := remoteClient.Put(data)\nif diags.HasErrors() && strings.Contains(diags.Err().Error(), \"expected on 1 response value\") {\n    log.Printf(\"consul txn returned unexpected result count; retrying once\")\n    diags = remoteClient.Put(data)\n}\nif diags.HasErrors() {\n    return fmt.Errorf(\"unexpected consul response shape (tf=%s, consul=%s): %w\", tfVersion, consulVersion, diags.Err())\n}","preventionTips":["Pin Consul and Terraform versions that are known-good together.","Capture full Txn responses in logs so hits can be reported upstream.","Don't rely on this branch being unreachable in custom forks; keep the assertion."],"tags":["consul","backend","defensive","bug"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}