{"record":{"id":"74094287a1811c37","repo":"hashicorp/terraform","slug":"unknown-view-type-v-740942","errorCode":null,"errorMessage":"unknown view type %v","messagePattern":"unknown view type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/views/modules.go","lineNumber":32,"sourceCode":"\t\"github.com/xlab/treeprint\"\n)\n\ntype Modules interface {\n\t// Display renders the list of module entries.\n\tDisplay(manifest moduleref.Manifest) int\n\n\t// Diagnostics renders early diagnostics, resulting from argument parsing.\n\tDiagnostics(diags tfdiags.Diagnostics)\n}\n\nfunc NewModules(vt arguments.ViewType, view *View) Modules {\n\tswitch vt {\n\tcase arguments.ViewJSON:\n\t\treturn &ModulesJSON{view: view}\n\tcase arguments.ViewHuman:\n\t\treturn &ModulesHuman{view: view}\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"unknown view type %v\", vt))\n\t}\n}\n\ntype ModulesHuman struct {\n\tview *View\n}\n\nvar _ Modules = (*ModulesHuman)(nil)\n\nfunc (v *ModulesHuman) Display(manifest moduleref.Manifest) int {\n\tif len(manifest.Records) == 0 {\n\t\tv.view.streams.Println(\"No modules found in configuration.\")\n\t\treturn 0\n\t}\n\tprintRoot := treeprint.New()\n\n\t// ensure output is deterministic\n\tsort.Sort(manifest.Records)","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/views/modules.go#L14-L50","documentation":"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').","triggerScenarios":"`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.","commonSituations":"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).","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."],"exampleFix":"// before\nmt := arguments.Modules{} // ViewType == ViewNone\nv := views.NewModules(mt.ViewType, view)\n// after\nmt := arguments.Modules{ViewType: arguments.ViewHuman}\nv := views.NewModules(mt.ViewType, view)","handlingStrategy":"type-guard","validationCode":"switch vt {\ncase arguments.ViewHuman, arguments.ViewJSON:\n  // ok\ndefault:\n  return fmt.Errorf(\"unsupported modules view type: %v\", vt)\n}","typeGuard":"func isValidModulesViewType(vt arguments.ViewType) bool {\n  return vt == arguments.ViewHuman || vt == arguments.ViewJSON\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["terraform-cli","views","modules","panic","invariant","view-type"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}