{"record":{"id":"6bbf16cf24ce3bd0","repo":"hashicorp/terraform","slug":"unknown-view-type-v-6bbf16","errorCode":null,"errorMessage":"unknown view type %v","messagePattern":"unknown view type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/views/output.go","lineNumber":40,"sourceCode":"\n// The Output view renders either one or all outputs, depending on whether or\n// not the name argument is empty.\ntype Output interface {\n\tOutput(name string, outputs map[string]*states.OutputValue) tfdiags.Diagnostics\n\tDiagnostics(diags tfdiags.Diagnostics)\n}\n\n// NewOutput returns an initialized Output implementation for the given ViewType.\nfunc NewOutput(vt arguments.ViewType, view *View) Output {\n\tswitch vt {\n\tcase arguments.ViewJSON:\n\t\treturn &OutputJSON{view: view}\n\tcase arguments.ViewRaw:\n\t\treturn &OutputRaw{view: view}\n\tcase arguments.ViewHuman:\n\t\treturn &OutputHuman{view: view}\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"unknown view type %v\", vt))\n\t}\n}\n\n// The OutputHuman implementation renders outputs in a format equivalent to HCL\n// source. This uses the same formatting logic as in the console REPL.\ntype OutputHuman struct {\n\tview *View\n}\n\nvar _ Output = (*OutputHuman)(nil)\n\nfunc (v *OutputHuman) Output(name string, outputs map[string]*states.OutputValue) tfdiags.Diagnostics {\n\tvar diags tfdiags.Diagnostics\n\n\tif len(outputs) == 0 {\n\t\tdiags = diags.Append(noOutputsWarning())\n\t\treturn diags\n\t}","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/views/output.go#L22-L58","documentation":"This panic fires in NewOutput when arguments.ViewType is not ViewJSON, ViewRaw, or ViewHuman. Output is one of the few view constructors that legitimately accepts ViewRaw, so the only unhandled values are ViewNone(0) and any future enum value.","triggerScenarios":"`terraform output` invoked with a ViewType the output constructor does not recognize: zero-value ViewType (test bypassing flag parsing), or a newly added ViewType without a matching case.","commonSituations":"A test constructs OutputArgs with the default zero ViewType. A maintainer adds a ViewType and forgets to extend NewOutput. CLI flag parsing only ever produces ViewJSON/ViewRaw/ViewHuman, so end users cannot trigger this.","solutions":["In tests/code calling NewOutput, set ViewType explicitly to one of ViewJSON, ViewRaw, or ViewHuman.","When extending arguments/types.go with a new ViewType, add a case to views/output.go:40 and the other New* switches.","Cover new cases with output_test.go."],"exampleFix":"// before\nout := arguments.Output{} // ViewType == ViewNone\nv := views.NewOutput(out.ViewType, view)\n// after\nout := arguments.Output{ViewType: arguments.ViewHuman}\nv := views.NewOutput(out.ViewType, view)","handlingStrategy":"type-guard","validationCode":"switch vt {\ncase arguments.ViewJSON, arguments.ViewRaw, arguments.ViewHuman:\n  // ok\ndefault:\n  return fmt.Errorf(\"unsupported output view type: %v\", vt)\n}","typeGuard":"func isValidOutputViewType(vt arguments.ViewType) bool {\n  return vt == arguments.ViewHuman || vt == arguments.ViewJSON || vt == arguments.ViewRaw\n}","tryCatchPattern":null,"preventionTips":["Set ViewType explicitly in arguments.Output test fixtures.","Add a case for any new ViewType to NewOutput (and sibling constructors).","Run output_test.go after touching the ViewType enum."],"tags":["terraform-cli","views","output","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"}