{"record":{"id":"37c89b4d292f06ab","repo":"hashicorp/terraform","slug":"unknown-view-type-v-37c89b","errorCode":null,"errorMessage":"unknown view type %v","messagePattern":"unknown view type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/views/init.go","lineNumber":52,"sourceCode":"\n\tprepareMessage(messageCode InitMessageCode, params ...any) string\n\n\tSpacer // The `init` command logs empty lines to space-out different sections of human-readable output\n}\n\n// NewInit returns Init implementation for the given ViewType.\nfunc NewInit(vt arguments.ViewType, view *View) Init {\n\tswitch vt {\n\tcase arguments.ViewJSON:\n\t\treturn &InitJSON{\n\t\t\tview: NewJSONView(view),\n\t\t}\n\tcase arguments.ViewHuman:\n\t\treturn &InitHuman{\n\t\t\tview: view,\n\t\t}\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"unknown view type %v\", vt))\n\t}\n}\n\n// The InitHuman implementation renders human-readable text logs, suitable for\n// a scrolling terminal.\ntype InitHuman struct {\n\tview *View\n}\n\nvar (\n\t_ Init                       = (*InitHuman)(nil)\n\t_ ProviderInstallationLogger = (*InitHuman)(nil)\n)\n\nfunc (v *InitHuman) Diagnostics(diags tfdiags.Diagnostics) {\n\tv.view.Diagnostics(diags)\n}\n","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/views/init.go#L34-L70","documentation":"This panic fires in NewInit when arguments.ViewType is neither ViewJSON nor ViewHuman. ViewType is `type ViewType rune`; the init switch has no case for ViewNone(0) or ViewRaw('R'), so either value (or any future unhandled rune) crashes here.","triggerScenarios":"`terraform init` invoked with a ViewType the init constructor does not handle: a zero-value ViewType (0) from code that skipped flag parsing, ViewRaw passed to init (not supported), or a newly added enum value without a matching case here.","commonSituations":"A test constructs InitArgs with the default zero ViewType. A maintainer introduces a new ViewType and forgets to extend NewInit. End users cannot trigger it because init flag parsing only ever produces ViewHuman or ViewJSON.","solutions":["In any code/test calling NewInit, set ViewType explicitly to arguments.ViewHuman or arguments.ViewJSON.","When adding a ViewType to arguments/types.go, add a case to every views.New* switch including views/init.go:52.","Cover the new case with a test in init_test.go."],"exampleFix":"// before\ncfg := arguments.Init{} // ViewType == ViewNone\nv := views.NewInit(cfg.ViewType, view)\n// after\ncfg := arguments.Init{ViewType: arguments.ViewHuman}\nv := views.NewInit(cfg.ViewType, view)","handlingStrategy":"type-guard","validationCode":"switch vt {\ncase arguments.ViewHuman, arguments.ViewJSON:\n  // ok\ndefault:\n  return fmt.Errorf(\"unsupported init view type: %v\", vt)\n}","typeGuard":"func isValidInitViewType(vt arguments.ViewType) bool {\n  return vt == arguments.ViewHuman || vt == arguments.ViewJSON\n}","tryCatchPattern":null,"preventionTips":["Set ViewType explicitly in every arguments.Init test fixture.","Keep all New* view switches in sync when extending the ViewType enum.","Add a sweep test iterating ViewType cases across all view constructors."],"tags":["terraform-cli","views","init","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"}