hashicorp/terraform · error
Failed to marshal get attr step name %#v
Error message
Failed to marshal get attr step name %#v: %s
What it means
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.
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.
Defensive patterns
Strategy: try-catch
Try / catch
if _, err := jsonplan.Marshal(plans); err != nil {
// This branch is effectively unreachable; if hit, suspect a swapped json encoder.
log.Printf("attr-step marshal failed unexpectedly: %v", err)
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Effectively only seen in test harnesses or build-time instrumentation that swaps the json encoder; not a realistic end-user failure.
Related errors
- Failed to marshal index step key %#v
- Unsupported path step %#v (%t)
- cannot decode tfvars from a null value
- could not decode output
- could not interpret output
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/9cc1a54b733992b3.
Report an issue: GitHub.
Appendix: source
Thrown at internal/command/jsonplan/plan.go:1078
}
return json.Marshal(jsonPaths)
}
func encodePath(path cty.Path) (json.RawMessage, error) {
steps := make([]json.RawMessage, 0, len(path))
for _, step := range path {
switch s := step.(type) {
case cty.IndexStep:
key, err := ctyjson.Marshal(s.Key, s.Key.Type())
if err != nil {
return nil, fmt.Errorf("Failed to marshal index step key %#v: %s", s.Key, err)
}
steps = append(steps, key)
case cty.GetAttrStep:
name, err := json.Marshal(s.Name)
if err != nil {
return nil, fmt.Errorf("Failed to marshal get attr step name %#v: %s", s.Name, err)
}
steps = append(steps, name)
default:
return nil, fmt.Errorf("Unsupported path step %#v (%t)", step, step)
}
}
return json.Marshal(steps)
}
View on GitHub (pinned to d32a084675)