hashicorp/terraform · critical
unknown view type %v
Error message
unknown view type %v
What it means
This panic fires in NewModules when arguments.ViewType is neither ViewJSON nor ViewHuman. ViewType is `type ViewType rune`; the modules switch has no case for ViewNone(0) or ViewRaw('R').
Source
Thrown at internal/command/views/modules.go:32
"github.com/xlab/treeprint"
)
type Modules interface {
// Display renders the list of module entries.
Display(manifest moduleref.Manifest) int
// Diagnostics renders early diagnostics, resulting from argument parsing.
Diagnostics(diags tfdiags.Diagnostics)
}
func NewModules(vt arguments.ViewType, view *View) Modules {
switch vt {
case arguments.ViewJSON:
return &ModulesJSON{view: view}
case arguments.ViewHuman:
return &ModulesHuman{view: view}
default:
panic(fmt.Sprintf("unknown view type %v", vt))
}
}
type ModulesHuman struct {
view *View
}
var _ Modules = (*ModulesHuman)(nil)
func (v *ModulesHuman) Display(manifest moduleref.Manifest) int {
if len(manifest.Records) == 0 {
v.view.streams.Println("No modules found in configuration.")
return 0
}
printRoot := treeprint.New()
// ensure output is deterministic
sort.Sort(manifest.Records)View on GitHub (pinned to d32a084675)
Solutions
- Set ViewType explicitly to arguments.ViewHuman or arguments.ViewJSON in any test calling NewModules.
- Add a case for any new ViewType to views/modules.go:32 (and all sibling New* constructors).
- Run `go test ./internal/command/views/` after changes to arguments/types.go.
Example fix
// before
mt := arguments.Modules{} // ViewType == ViewNone
v := views.NewModules(mt.ViewType, view)
// after
mt := arguments.Modules{ViewType: arguments.ViewHuman}
v := views.NewModules(mt.ViewType, view) Defensive patterns
Strategy: type-guard
Validate before calling
switch vt {
case arguments.ViewHuman, arguments.ViewJSON:
// ok
default:
return fmt.Errorf("unsupported modules view type: %v", vt)
} Type guard
func isValidModulesViewType(vt arguments.ViewType) bool {
return vt == arguments.ViewHuman || vt == arguments.ViewJSON
} Prevention
- Set ViewType explicitly in arguments.Modules test fixtures.
- Extend NewModules whenever the ViewType enum grows.
- Run the views test suite after editing arguments/types.go.
When it happens
Trigger: `terraform providers` / modules-listing command invoked with a ViewType the modules constructor does not recognize: zero-value ViewType (test code skipping flag parsing), ViewRaw passed to modules (not supported), or a future enum value without a matching case.
Common situations: A test builds a Modules view with the default zero ViewType. A maintainer adds a ViewType and forgets to extend NewModules. End users cannot trigger it via flags (parsing only yields 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/74094287a1811c37.
Report an issue: GitHub.