hashicorp/terraform · critical
unknown view type
Error message
unknown view type %v
What it means
This panic fires in NewShow when arguments.ViewType is neither ViewJSON nor ViewHuman. ViewType is `type ViewType rune`; the show switch has no case for ViewNone(0) or ViewRaw('R').
Solutions
- In any code/test calling NewShow, set ViewType explicitly to arguments.ViewHuman or arguments.ViewJSON.
- When adding a ViewType to arguments/types.go, add a case to views/show.go:43 and every sibling New* switch.
- Cover the new case with show_test.go.
Example fix
// before
s := arguments.Show{} // ViewType == ViewNone
v := views.NewShow(s.ViewType, view)
// after
s := arguments.Show{ViewType: arguments.ViewHuman}
v := views.NewShow(s.ViewType, view) Defensive patterns
Strategy: type-guard
Validate before calling
switch vt {
case arguments.ViewHuman, arguments.ViewJSON:
// ok
default:
return fmt.Errorf("unsupported show view type: %v", vt)
} Type guard
func isValidShowViewType(vt arguments.ViewType) bool {
return vt == arguments.ViewHuman || vt == arguments.ViewJSON
} Prevention
- Set ViewType explicitly in arguments.Show test fixtures.
- Add a case for any new ViewType to NewShow (and sibling constructors).
- Run show_test.go after touching arguments/types.go.
When it happens
Trigger: `terraform show` invoked with a ViewType the show constructor does not recognize: zero-value ViewType from code that skipped flag parsing, ViewRaw passed to show (not supported here), or a newly added enum value without a matching case.
Common situations: A test constructs ShowArgs with the default zero ViewType. A maintainer adds a ViewType and forgets to extend NewShow. End users cannot trigger it via flags.
Related errors
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/acefef3f138afce0.
Report an issue: GitHub.
Appendix: source
Thrown at internal/command/views/show.go:43
type Show interface {
// Display renders the plan, if it is available. If plan is nil, it renders the statefile.
Display(config *configs.Config, plan *plans.Plan, planJSON *cloudplan.RemotePlanJSON, stateFile *statefile.File, schemas *terraform.Schemas) int
// Diagnostics renders early diagnostics, resulting from argument parsing.
Diagnostics(diags tfdiags.Diagnostics)
// DisplayResourceInstanceState displays the state for a single resource instance. Diagnostics from the state show command are included in the json output.
DisplayResourceInstanceState(jsonformat.State, tfdiags.Diagnostics) int
}
func NewShow(vt arguments.ViewType, view *View) Show {
switch vt {
case arguments.ViewJSON:
return &ShowJSON{view: view}
case arguments.ViewHuman:
return &ShowHuman{view: view}
default:
panic(fmt.Sprintf("unknown view type %v", vt))
}
}
type ShowHuman struct {
view *View
}
var _ Show = (*ShowHuman)(nil)
func (v *ShowHuman) DisplayResourceInstanceState(state jsonformat.State, diags tfdiags.Diagnostics) int {
renderer := jsonformat.Renderer{
Streams: v.view.streams,
Colorize: v.view.colorize,
RunningInAutomation: v.view.runningInAutomation,
}
if diags.HasErrors() {
v.Diagnostics(diags)View on GitHub (pinned to d32a084675)