hashicorp/terraform · critical
unknown view type %v
Error message
unknown view type %v
What it means
NewTest (internal/command/views/test.go:84) switches over arguments.ViewType and returns TestJSON for ViewJSON or TestHuman for ViewHuman; any other value panics 'unknown view type %v'. 'terraform test' only supports human and JSON output.
Source
Thrown at internal/command/views/test.go:95
// status of their ongoing remote test run.
TFCStatusUpdate(status tfe.TestRunStatus, elapsed time.Duration)
// TFCRetryHook prints an update if a request failed and is being retried.
TFCRetryHook(attemptNum int, resp *http.Response)
}
func NewTest(vt arguments.ViewType, view *View) Test {
switch vt {
case arguments.ViewJSON:
return &TestJSON{
view: NewJSONView(view),
}
case arguments.ViewHuman:
return &TestHuman{
view: view,
}
default:
panic(fmt.Sprintf("unknown view type %v", vt))
}
}
type TestHuman struct {
CloudHooks
view *View
}
var _ Test = (*TestHuman)(nil)
func (t *TestHuman) Abstract(_ *moduletest.Suite) {
// Do nothing, we don't print an abstract for the human view.
}
func (t *TestHuman) Conclusion(suite *moduletest.Suite) {
t.view.streams.Println()
View on GitHub (pinned to d32a084675)
Solutions
- Ensure every constructor of arguments.Test sets ViewType explicitly (default to ViewHuman when -json is absent).
- If introducing a new ViewType, add the corresponding Test implementation and its case here together.
- Add a test covering NewTest for each defined ViewType constant.
- As an end user, report the internal bug with the 'terraform test' invocation that crashed.
Defensive patterns
Strategy: validation
Validate before calling
func validTestViewType(vt arguments.ViewType) bool {
return vt == arguments.ViewHuman || vt == arguments.ViewJSON
}
if !validTestViewType(args.ViewType) {
return nil, fmt.Errorf("terraform test requires ViewHuman or ViewJSON, got %v", args.ViewType)
} Prevention
- Default ViewType to ViewHuman in the test argument parser when -json is absent.
- Cover NewTest for every defined ViewType constant in a unit test.
- When adding a ViewType, add the matching Test implementation and its case together.
When it happens
Trigger: NewTest is called with ViewRaw ('R'), ViewNone (0), or any rune other than ViewHuman/ViewJSON. The test argument parser (internal/command/arguments/test.go) only ever sets ViewJSON or ViewHuman, so reaching the panic implies an uninitialized/leaked ViewType or a new view mode added without a Test implementation.
Common situations: A code path constructing arguments.Test{} without setting ViewType (leaving ViewNone), or a future ViewType constant introduced without a Test view variant.
Related errors
- unknown view type %v
- unrecognized test progress: %s
- unrecognized status: %s
- (*StateMigrateHuman)LogStateMigrationErrored: called incorre
- missing message for InstallingProviderMessage init message c
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/142aaf5af166423d.
Report an issue: GitHub.