{"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":"console","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/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/jsonplan/plan.go#L1060-L1087","documentation":"In encodePath, json.Marshal(s.Name) for a cty.GetAttrStep name failed. s.Name is a Go string; json.Marshal of a string fails only when the bytes are not valid UTF-8. So this error indicates a malformed attribute name in a path.","triggerScenarios":"A GetAttrStep whose Name contains invalid UTF-8 bytes. Reachable via any path encoding (relevant attributes or replace_paths).","commonSituations":"Extremely rare. A provider schema returning an attribute name that is not valid UTF-8, or a corrupted path/state; essentially an invariant violation since schema attribute names are expected to be valid identifiers.","solutions":["Report as a bug; attribute names are expected to be valid UTF-8 identifiers.","Identify the schema/attribute producing the invalid name (often a provider issue).","Avoid or sanitize the configuration path that surfaces the bad attribute name."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate GetAttrStep names are valid UTF-8 before marshaling.\nfor _, ra := range plan.RelevantAttributes {\n    for _, step := range ra.Attr {\n        if gas, ok := step.(cty.GetAttrStep); ok {\n            if !utf8.ValidString(gas.Name) {\n                return fmt.Errorf(\"invalid UTF-8 attribute name %q in relevant attribute path\", gas.Name)\n            }\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"out, err := jsonplan.Marshal(config, plan, sf, schemas)\nif err != nil && strings.Contains(err.Error(), \"marshal get attr step name\") {\n    // an attribute name is not valid UTF-8; likely a provider schema bug\n}\nreturn err","preventionTips":["Treat invalid-UTF-8 attribute names as a provider/schema bug and report it.","Validate provider schema attribute names are ASCII identifiers when building schemas.","Capture the %#v name value in diagnostics to locate the offending schema."],"tags":["paths","marshal","utf8"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}