hashicorp/terraform · critical
unknown view type %v
Error message
unknown view type %v
What it means
This panic fires in NewApply when the supplied arguments.ViewType is neither ViewJSON nor ViewHuman. ViewType is `type ViewType rune` (ViewNone=0, ViewHuman='H', ViewJSON='J', ViewRaw='R'); the apply switch omits ViewRaw and ViewNone, so any unhandled value crashes here.
Source
Thrown at internal/command/views/apply.go:46
// NewApply returns an initialized Apply implementation for the given ViewType.
func NewApply(vt arguments.ViewType, destroy bool, view *View) Apply {
switch vt {
case arguments.ViewJSON:
return &ApplyJSON{
view: NewJSONView(view),
destroy: destroy,
countHook: &countHook{},
}
case arguments.ViewHuman:
return &ApplyHuman{
view: view,
destroy: destroy,
inAutomation: view.RunningInAutomation(),
countHook: &countHook{},
}
default:
panic(fmt.Sprintf("unknown view type %v", vt))
}
}
// The ApplyHuman implementation renders human-readable text logs, suitable for
// a scrolling terminal.
type ApplyHuman struct {
view *View
destroy bool
inAutomation bool
countHook *countHook
}
var _ Apply = (*ApplyHuman)(nil)
func (v *ApplyHuman) ResourceCount(stateOutPath string) {
var summary stringView on GitHub (pinned to d32a084675)
Solutions
- If writing a test that calls NewApply, always set ViewType to arguments.ViewHuman or arguments.ViewJSON explicitly.
- If you added a new ViewType, add a matching case to the switch in views/apply.go:46 (and all sibling New* constructors).
- Use `go test ./internal/command/views/` to reproduce and confirm the case is handled.
Example fix
// before — test bypasses flag parsing, ViewType is zero
cfg := arguments.Apply{ /* ViewType unset -> ViewNone */ }
apply := views.NewApply(cfg.ViewType, view)
// after
cfg := arguments.Apply{ViewType: arguments.ViewHuman}
apply := views.NewApply(cfg.ViewType, view) Defensive patterns
Strategy: type-guard
Validate before calling
// Ensure a known ViewType before constructing the view.
switch vt {
case arguments.ViewHuman, arguments.ViewJSON:
// ok
default:
return fmt.Errorf("unsupported apply view type: %v", vt)
} Type guard
// Guard for the apply view.
func isValidApplyViewType(vt arguments.ViewType) bool {
return vt == arguments.ViewHuman || vt == arguments.ViewJSON
} Prevention
- Never construct arguments.Apply{} with an unset ViewType in tests.
- When adding a ViewType, update every views.New* switch in one commit.
- Run the views test suite after touching arguments/types.go.
When it happens
Trigger: `terraform apply` (or destroy) with a ViewType that the apply view constructor does not recognize. Realistically: a zero-value ViewType (0, when argument parsing was skipped/bypassed, as tests do), passing ViewRaw to apply (unsupported), or a future new ViewType added to the enum without updating this switch.
Common situations: Internal/test code that constructs an ApplyArgs without setting ViewType (defaults to ViewNone=0). A maintainer adds a new ViewType (e.g. ViewMachine) to arguments/types.go and forgets to add a case to NewApply. Not triggerable by end users via CLI flags because flag parsing only ever sets ViewHuman or ViewJSON.
Related errors
- unknown view type %v
- unknown view type %v
- unknown view type %v
- unknown view type %v
- unknown view type %v
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/65e3ba81bd20ff42.
Report an issue: GitHub.