hashicorp/terraform · critical
unknown view type %v
Error message
unknown view type %v
What it means
This panic fires in NewOutput when arguments.ViewType is not ViewJSON, ViewRaw, or ViewHuman. Output is one of the few view constructors that legitimately accepts ViewRaw, so the only unhandled values are ViewNone(0) and any future enum value.
Source
Thrown at internal/command/views/output.go:40
// The Output view renders either one or all outputs, depending on whether or
// not the name argument is empty.
type Output interface {
Output(name string, outputs map[string]*states.OutputValue) tfdiags.Diagnostics
Diagnostics(diags tfdiags.Diagnostics)
}
// NewOutput returns an initialized Output implementation for the given ViewType.
func NewOutput(vt arguments.ViewType, view *View) Output {
switch vt {
case arguments.ViewJSON:
return &OutputJSON{view: view}
case arguments.ViewRaw:
return &OutputRaw{view: view}
case arguments.ViewHuman:
return &OutputHuman{view: view}
default:
panic(fmt.Sprintf("unknown view type %v", vt))
}
}
// The OutputHuman implementation renders outputs in a format equivalent to HCL
// source. This uses the same formatting logic as in the console REPL.
type OutputHuman struct {
view *View
}
var _ Output = (*OutputHuman)(nil)
func (v *OutputHuman) Output(name string, outputs map[string]*states.OutputValue) tfdiags.Diagnostics {
var diags tfdiags.Diagnostics
if len(outputs) == 0 {
diags = diags.Append(noOutputsWarning())
return diags
}View on GitHub (pinned to d32a084675)
Solutions
- In tests/code calling NewOutput, set ViewType explicitly to one of ViewJSON, ViewRaw, or ViewHuman.
- When extending arguments/types.go with a new ViewType, add a case to views/output.go:40 and the other New* switches.
- Cover new cases with output_test.go.
Example fix
// before
out := arguments.Output{} // ViewType == ViewNone
v := views.NewOutput(out.ViewType, view)
// after
out := arguments.Output{ViewType: arguments.ViewHuman}
v := views.NewOutput(out.ViewType, view) Defensive patterns
Strategy: type-guard
Validate before calling
switch vt {
case arguments.ViewJSON, arguments.ViewRaw, arguments.ViewHuman:
// ok
default:
return fmt.Errorf("unsupported output view type: %v", vt)
} Type guard
func isValidOutputViewType(vt arguments.ViewType) bool {
return vt == arguments.ViewHuman || vt == arguments.ViewJSON || vt == arguments.ViewRaw
} Prevention
- Set ViewType explicitly in arguments.Output test fixtures.
- Add a case for any new ViewType to NewOutput (and sibling constructors).
- Run output_test.go after touching the ViewType enum.
When it happens
Trigger: `terraform output` invoked with a ViewType the output constructor does not recognize: zero-value ViewType (test bypassing flag parsing), or a newly added ViewType without a matching case.
Common situations: A test constructs OutputArgs with the default zero ViewType. A maintainer adds a ViewType and forgets to extend NewOutput. CLI flag parsing only ever produces ViewJSON/ViewRaw/ViewHuman, so end users cannot trigger this.
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/6bbf16cf24ce3bd0.
Report an issue: GitHub.