hashicorp/terraform · critical
unknown view type %v
Error message
unknown view type %v
What it means
This panic fires in NewInit when arguments.ViewType is neither ViewJSON nor ViewHuman. ViewType is `type ViewType rune`; the init switch has no case for ViewNone(0) or ViewRaw('R'), so either value (or any future unhandled rune) crashes here.
Source
Thrown at internal/command/views/init.go:52
prepareMessage(messageCode InitMessageCode, params ...any) string
Spacer // The `init` command logs empty lines to space-out different sections of human-readable output
}
// NewInit returns Init implementation for the given ViewType.
func NewInit(vt arguments.ViewType, view *View) Init {
switch vt {
case arguments.ViewJSON:
return &InitJSON{
view: NewJSONView(view),
}
case arguments.ViewHuman:
return &InitHuman{
view: view,
}
default:
panic(fmt.Sprintf("unknown view type %v", vt))
}
}
// The InitHuman implementation renders human-readable text logs, suitable for
// a scrolling terminal.
type InitHuman struct {
view *View
}
var (
_ Init = (*InitHuman)(nil)
_ ProviderInstallationLogger = (*InitHuman)(nil)
)
func (v *InitHuman) Diagnostics(diags tfdiags.Diagnostics) {
v.view.Diagnostics(diags)
}
View on GitHub (pinned to d32a084675)
Solutions
- In any code/test calling NewInit, set ViewType explicitly to arguments.ViewHuman or arguments.ViewJSON.
- When adding a ViewType to arguments/types.go, add a case to every views.New* switch including views/init.go:52.
- Cover the new case with a test in init_test.go.
Example fix
// before
cfg := arguments.Init{} // ViewType == ViewNone
v := views.NewInit(cfg.ViewType, view)
// after
cfg := arguments.Init{ViewType: arguments.ViewHuman}
v := views.NewInit(cfg.ViewType, view) Defensive patterns
Strategy: type-guard
Validate before calling
switch vt {
case arguments.ViewHuman, arguments.ViewJSON:
// ok
default:
return fmt.Errorf("unsupported init view type: %v", vt)
} Type guard
func isValidInitViewType(vt arguments.ViewType) bool {
return vt == arguments.ViewHuman || vt == arguments.ViewJSON
} Prevention
- Set ViewType explicitly in every arguments.Init test fixture.
- Keep all New* view switches in sync when extending the ViewType enum.
- Add a sweep test iterating ViewType cases across all view constructors.
When it happens
Trigger: `terraform init` invoked with a ViewType the init constructor does not handle: a zero-value ViewType (0) from code that skipped flag parsing, ViewRaw passed to init (not supported), or a newly added enum value without a matching case here.
Common situations: A test constructs InitArgs with the default zero ViewType. A maintainer introduces a new ViewType and forgets to extend NewInit. End users cannot trigger it because init flag parsing only ever produces ViewHuman or ViewJSON.
Related errors
- unknown view type %v
- unexpected empty message for init message code: %s
- 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/37c89b4d292f06ab.
Report an issue: GitHub.