{"record":{"id":"65e3ba81bd20ff42","repo":"hashicorp/terraform","slug":"unknown-view-type-v","errorCode":null,"errorMessage":"unknown view type %v","messagePattern":"unknown view type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/views/apply.go","lineNumber":46,"sourceCode":"\n// NewApply returns an initialized Apply implementation for the given ViewType.\nfunc NewApply(vt arguments.ViewType, destroy bool, view *View) Apply {\n\tswitch vt {\n\tcase arguments.ViewJSON:\n\t\treturn &ApplyJSON{\n\t\t\tview:      NewJSONView(view),\n\t\t\tdestroy:   destroy,\n\t\t\tcountHook: &countHook{},\n\t\t}\n\tcase arguments.ViewHuman:\n\t\treturn &ApplyHuman{\n\t\t\tview:         view,\n\t\t\tdestroy:      destroy,\n\t\t\tinAutomation: view.RunningInAutomation(),\n\t\t\tcountHook:    &countHook{},\n\t\t}\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"unknown view type %v\", vt))\n\t}\n}\n\n// The ApplyHuman implementation renders human-readable text logs, suitable for\n// a scrolling terminal.\ntype ApplyHuman struct {\n\tview *View\n\n\tdestroy      bool\n\tinAutomation bool\n\n\tcountHook *countHook\n}\n\nvar _ Apply = (*ApplyHuman)(nil)\n\nfunc (v *ApplyHuman) ResourceCount(stateOutPath string) {\n\tvar summary string","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/views/apply.go#L28-L64","documentation":"This panic fires in NewApply when the supplied arguments.ViewType is neither ViewJSON nor ViewHuman. ViewType is `type ViewType rune` (ViewNone=0, ViewHuman='H', ViewJSON='J', ViewRaw='R'); the apply switch omits ViewRaw and ViewNone, so any unhandled value crashes here.","triggerScenarios":"`terraform apply` (or destroy) with a ViewType that the apply view constructor does not recognize. Realistically: a zero-value ViewType (0, when argument parsing was skipped/bypassed, as tests do), passing ViewRaw to apply (unsupported), or a future new ViewType added to the enum without updating this switch.","commonSituations":"Internal/test code that constructs an ApplyArgs without setting ViewType (defaults to ViewNone=0). A maintainer adds a new ViewType (e.g. ViewMachine) to arguments/types.go and forgets to add a case to NewApply. Not triggerable by end users via CLI flags because flag parsing only ever sets ViewHuman or ViewJSON.","solutions":["If writing a test that calls NewApply, always set ViewType to arguments.ViewHuman or arguments.ViewJSON explicitly.","If you added a new ViewType, add a matching case to the switch in views/apply.go:46 (and all sibling New* constructors).","Use `go test ./internal/command/views/` to reproduce and confirm the case is handled."],"exampleFix":"// before — test bypasses flag parsing, ViewType is zero\ncfg := arguments.Apply{ /* ViewType unset -> ViewNone */ }\napply := views.NewApply(cfg.ViewType, view)\n// after\ncfg := arguments.Apply{ViewType: arguments.ViewHuman}\napply := views.NewApply(cfg.ViewType, view)","handlingStrategy":"type-guard","validationCode":"// Ensure a known ViewType before constructing the view.\nswitch vt {\ncase arguments.ViewHuman, arguments.ViewJSON:\n  // ok\ndefault:\n  return fmt.Errorf(\"unsupported apply view type: %v\", vt)\n}","typeGuard":"// Guard for the apply view.\nfunc isValidApplyViewType(vt arguments.ViewType) bool {\n  return vt == arguments.ViewHuman || vt == arguments.ViewJSON\n}","tryCatchPattern":null,"preventionTips":["Never construct arguments.Apply{} with an unset ViewType in tests.","When adding a ViewType, update every views.New* switch in one commit.","Run the views test suite after touching arguments/types.go."],"tags":["terraform-cli","views","apply","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"}