{"record":{"id":"9cc1a54b733992b3","repo":"hashicorp/terraform","slug":"failed-to-marshal-get-attr-step-name-v-s","errorCode":null,"errorMessage":"Failed to marshal get attr step name %#v: %s","messagePattern":"Failed to marshal get attr step name %#v: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/jsonplan/plan.go","lineNumber":1078,"sourceCode":"\t}\n\n\treturn json.Marshal(jsonPaths)\n}\n\nfunc encodePath(path cty.Path) (json.RawMessage, error) {\n\tsteps := make([]json.RawMessage, 0, len(path))\n\tfor _, step := range path {\n\t\tswitch s := step.(type) {\n\t\tcase cty.IndexStep:\n\t\t\tkey, err := ctyjson.Marshal(s.Key, s.Key.Type())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"Failed to marshal index step key %#v: %s\", s.Key, err)\n\t\t\t}\n\t\t\tsteps = append(steps, key)\n\t\tcase cty.GetAttrStep:\n\t\t\tname, err := json.Marshal(s.Name)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"Failed to marshal get attr step name %#v: %s\", s.Name, err)\n\t\t\t}\n\t\t\tsteps = append(steps, name)\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"Unsupported path step %#v (%t)\", step, step)\n\t\t}\n\t}\n\treturn json.Marshal(steps)\n}\n","sourceCodeStart":1060,"sourceCodeEnd":1087,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/jsonplan/plan.go#L1060-L1087","documentation":"Thrown by jsonplan.encodePath for a cty.GetAttrStep: the attribute name (a Go string) is passed to encoding/json.Marshal and that call failed. Because s.Name is an ordinary string, this branch is virtually unreachable under normal operation; hitting it implies memory corruption, an extremely unusual rune set, or a json encoder whose Encode method was replaced/misconfigured.","triggerScenarios":"A GetAttrStep.Name value that the json encoder cannot serialize; a customized/monkey-patched json.Marshal in the process; an empty struct masquerading as a string due to unsafe casts.","commonSituations":"Effectively only seen in test harnesses or build-time instrumentation that swaps the json encoder; not a realistic end-user failure.","solutions":["Upgrade Terraform to rule out a transient/tooling issue.","Inspect whether any linked code overrides encoding/json behavior.","Report upstream with the %#v of the name from the message."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, err := jsonplan.Marshal(plans); err != nil {\n    // This branch is effectively unreachable; if hit, suspect a swapped json encoder.\n    log.Printf(\"attr-step marshal failed unexpectedly: %v\", err)\n    return err\n}","preventionTips":["Do not override or wrap encoding/json with a non-standard encoder in the process.","Treat this error as a tooling/environment defect first, not a configuration issue."],"tags":["terraform","json-plan","cty","path-encoding","unreachable"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}