{"record":{"id":"a45d0c1d786f1d0d","repo":"hashicorp/terraform","slug":"unknown-view-type-v-a45d0c","errorCode":null,"errorMessage":"unknown view type %v","messagePattern":"unknown view type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/views/operation.go","lineNumber":48,"sourceCode":"\n\tEmergencyDumpState(stateFile *statefile.File) error\n\n\tPlannedChange(change *plans.ResourceInstanceChangeSrc)\n\tPlan(plan *plans.Plan, schemas *terraform.Schemas)\n\tPlanNextStep(planPath string, genConfigPath string)\n\n\tDiagnostics(diags tfdiags.Diagnostics)\n\n\tPolicyDiagnostics(diags policy.Diagnostics)\n\tPolicyResult(addr string, resp policy.EvaluationResponse)\n}\n\nfunc NewOperation(vt arguments.ViewType, inAutomation bool, view *View) Operation {\n\tswitch vt {\n\tcase arguments.ViewHuman:\n\t\treturn &OperationHuman{view: view, inAutomation: inAutomation}\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"unknown view type %v\", vt))\n\t}\n}\n\ntype OperationHuman struct {\n\tview *View\n\n\t// inAutomation indicates that commands are being run by an\n\t// automated system rather than directly at a command prompt.\n\t//\n\t// This is a hint not to produce messages that expect that a user can\n\t// run a follow-up command, perhaps because Terraform is running in\n\t// some sort of workflow automation tool that abstracts away the\n\t// exact commands that are being run.\n\tinAutomation bool\n}\n\nvar _ Operation = (*OperationHuman)(nil)\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/views/operation.go#L30-L66","documentation":"This panic fires in NewOperation when arguments.ViewType is not ViewHuman — the operation switch only handles ViewHuman and falls through to default for anything else, including ViewJSON and ViewNone.","triggerScenarios":"Constructing an Operation view with a ViewType other than ViewHuman. The Operation view is a building block wrapped by other view types (Plan/Apply/Refresh), so this is typically triggered indirectly when a caller passes ViewJSON or ViewNone into NewOperation instead of the dedicated JSON operation path.","commonSituations":"A refactor changes how the Operation view is obtained (e.g. a caller that used to branch on ViewJSON now always calls NewOperation), or test code constructs an Operation with the zero ViewType. End users do not pass ViewType to NewOperation directly.","solutions":["Check the caller of NewOperation: it should only be invoked in the human-readable code path; JSON output should construct the JSON-specific operation view directly.","Ensure any test calling NewOperation passes arguments.ViewHuman.","If a new ViewType is added, decide whether Operation should support it and add a case accordingly."],"exampleFix":"// before — caller always routes through NewOperation\nop := views.NewOperation(args.ViewType, inAutomation, view) // crashes on ViewJSON\n// after — branch before calling\nvar op views.Operation\nif args.ViewType == arguments.ViewJSON {\n  op = /* json operation construction */\n} else {\n  op = views.NewOperation(arguments.ViewHuman, inAutomation, view)\n}","handlingStrategy":"type-guard","validationCode":"if vt != arguments.ViewHuman {\n  return fmt.Errorf(\"NewOperation only supports human view, got: %v\", vt)\n}","typeGuard":"func isHumanView(vt arguments.ViewType) bool {\n  return vt == arguments.ViewHuman\n}","tryCatchPattern":null,"preventionTips":["Only call NewOperation from the human-readable code path; JSON paths use their own operation view.","Branch on ViewType before constructing Operation, not inside it.","Document that NewOperation is human-only in its godoc."],"tags":["terraform-cli","views","operation","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"}