hashicorp/terraform · critical

unknown view type %v

Error message

unknown view type %v

What it means

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').

Source

Thrown at internal/command/views/plan.go:36

	Diagnostics(diags tfdiags.Diagnostics)
	HelpPrompt()
}

// NewPlan returns an initialized Plan implementation for the given ViewType.
func NewPlan(vt arguments.ViewType, view *View) Plan {
	switch vt {
	case arguments.ViewJSON:
		return &PlanJSON{
			view: NewJSONView(view),
		}
	case arguments.ViewHuman:
		return &PlanHuman{
			view:         view,
			inAutomation: view.RunningInAutomation(),
		}
	default:
		panic(fmt.Sprintf("unknown view type %v", vt))
	}
}

// The PlanHuman implementation renders human-readable text logs, suitable for
// a scrolling terminal.
type PlanHuman struct {
	view *View

	inAutomation bool
}

var _ Plan = (*PlanHuman)(nil)

func (v *PlanHuman) Operation() Operation {
	return NewOperation(arguments.ViewHuman, v.inAutomation, v.view)
}

func (v *PlanHuman) Hooks() []terraform.Hook {

View on GitHub (pinned to d32a084675)

Solutions

  1. Always set ViewType to arguments.ViewHuman or arguments.ViewJSON in any code/test calling NewPlan.
  2. Add a matching case to views/plan.go:36 for any new ViewType (and keep all sibling New* switches in sync).
  3. Run `go test ./internal/command/views/` to catch the regression.

Example fix

// before
p := arguments.Plan{} // ViewType == ViewNone
v := views.NewPlan(p.ViewType, view)
// after
p := arguments.Plan{ViewType: arguments.ViewHuman}
v := views.NewPlan(p.ViewType, view)
Defensive patterns

Strategy: type-guard

Validate before calling

switch vt {
case arguments.ViewHuman, arguments.ViewJSON:
  // ok
default:
  return fmt.Errorf("unsupported plan view type: %v", vt)
}

Type guard

func isValidPlanViewType(vt arguments.ViewType) bool {
  return vt == arguments.ViewHuman || vt == arguments.ViewJSON
}

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Related errors


AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11). Data as JSON: /api/errors/c2a917dc116fc2fa. Report an issue: GitHub.