hashicorp/terraform · critical
unknown view type %v
Error message
unknown view type %v
What it means
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.
Source
Thrown at internal/command/views/operation.go:48
EmergencyDumpState(stateFile *statefile.File) error
PlannedChange(change *plans.ResourceInstanceChangeSrc)
Plan(plan *plans.Plan, schemas *terraform.Schemas)
PlanNextStep(planPath string, genConfigPath string)
Diagnostics(diags tfdiags.Diagnostics)
PolicyDiagnostics(diags policy.Diagnostics)
PolicyResult(addr string, resp policy.EvaluationResponse)
}
func NewOperation(vt arguments.ViewType, inAutomation bool, view *View) Operation {
switch vt {
case arguments.ViewHuman:
return &OperationHuman{view: view, inAutomation: inAutomation}
default:
panic(fmt.Sprintf("unknown view type %v", vt))
}
}
type OperationHuman struct {
view *View
// inAutomation indicates that commands are being run by an
// automated system rather than directly at a command prompt.
//
// This is a hint not to produce messages that expect that a user can
// run a follow-up command, perhaps because Terraform is running in
// some sort of workflow automation tool that abstracts away the
// exact commands that are being run.
inAutomation bool
}
var _ Operation = (*OperationHuman)(nil)
View on GitHub (pinned to d32a084675)
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.
Example fix
// before — caller always routes through NewOperation
op := views.NewOperation(args.ViewType, inAutomation, view) // crashes on ViewJSON
// after — branch before calling
var op views.Operation
if args.ViewType == arguments.ViewJSON {
op = /* json operation construction */
} else {
op = views.NewOperation(arguments.ViewHuman, inAutomation, view)
} Defensive patterns
Strategy: type-guard
Validate before calling
if vt != arguments.ViewHuman {
return fmt.Errorf("NewOperation only supports human view, got: %v", vt)
} Type guard
func isHumanView(vt arguments.ViewType) bool {
return vt == arguments.ViewHuman
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- unknown view type %v
- unknown view type %v
- unknown view type %v
- unknown view type %v
- unknown view type %v
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/a45d0c1d786f1d0d.
Report an issue: GitHub.