{"record":{"id":"c2a917dc116fc2fa","repo":"hashicorp/terraform","slug":"unknown-view-type-v-c2a917","errorCode":null,"errorMessage":"unknown view type %v","messagePattern":"unknown view type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/views/plan.go","lineNumber":36,"sourceCode":"\n\tDiagnostics(diags tfdiags.Diagnostics)\n\tHelpPrompt()\n}\n\n// NewPlan returns an initialized Plan implementation for the given ViewType.\nfunc NewPlan(vt arguments.ViewType, view *View) Plan {\n\tswitch vt {\n\tcase arguments.ViewJSON:\n\t\treturn &PlanJSON{\n\t\t\tview: NewJSONView(view),\n\t\t}\n\tcase arguments.ViewHuman:\n\t\treturn &PlanHuman{\n\t\t\tview:         view,\n\t\t\tinAutomation: view.RunningInAutomation(),\n\t\t}\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"unknown view type %v\", vt))\n\t}\n}\n\n// The PlanHuman implementation renders human-readable text logs, suitable for\n// a scrolling terminal.\ntype PlanHuman struct {\n\tview *View\n\n\tinAutomation bool\n}\n\nvar _ Plan = (*PlanHuman)(nil)\n\nfunc (v *PlanHuman) Operation() Operation {\n\treturn NewOperation(arguments.ViewHuman, v.inAutomation, v.view)\n}\n\nfunc (v *PlanHuman) Hooks() []terraform.Hook {","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/views/plan.go#L18-L54","documentation":"This panic fires in NewPlan when arguments.ViewType is neither ViewJSON nor ViewHuman. ViewType is `type ViewType rune`; the plan switch has no case for ViewNone(0) or ViewRaw('R').","triggerScenarios":"`terraform plan` invoked with a ViewType the plan constructor does not recognize: zero-value ViewType from code that skipped flag parsing, ViewRaw passed to plan (unsupported), or a future enum value without a matching case.","commonSituations":"A test builds a Plan view with the default zero ViewType. A maintainer introduces a new ViewType and forgets to add a case to NewPlan. End users cannot trigger it via CLI flags.","solutions":["Always set ViewType to arguments.ViewHuman or arguments.ViewJSON in any code/test calling NewPlan.","Add a matching case to views/plan.go:36 for any new ViewType (and keep all sibling New* switches in sync).","Run `go test ./internal/command/views/` to catch the regression."],"exampleFix":"// before\np := arguments.Plan{} // ViewType == ViewNone\nv := views.NewPlan(p.ViewType, view)\n// after\np := arguments.Plan{ViewType: arguments.ViewHuman}\nv := views.NewPlan(p.ViewType, view)","handlingStrategy":"type-guard","validationCode":"switch vt {\ncase arguments.ViewHuman, arguments.ViewJSON:\n  // ok\ndefault:\n  return fmt.Errorf(\"unsupported plan view type: %v\", vt)\n}","typeGuard":"func isValidPlanViewType(vt arguments.ViewType) bool {\n  return vt == arguments.ViewHuman || vt == arguments.ViewJSON\n}","tryCatchPattern":null,"preventionTips":["Set ViewType explicitly in arguments.Plan test fixtures.","Keep NewPlan in sync with ViewType enum changes.","Run plan_test.go after editing the enum."],"tags":["terraform-cli","views","plan","panic","invariant","view-type"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}