{"record":{"id":"efa6cf94d2587f8c","repo":"hashicorp/terraform","slug":"unsupported-view-type-s","errorCode":null,"errorMessage":"unsupported view type: %s","messagePattern":"unsupported view type: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/views/state_migrate.go","lineNumber":87,"sourceCode":"\tLogMigrationSourceInitializationStart()\n\tLogMigrationSourceInitializationComplete()\n\tLogMigrationDestinationInitializationStart()\n\tLogMigrationDestinationInitializationComplete()\n\n\tProviderInstallationLogger\n\tProviderLockingLogger\n\n\tStateStoreProviderTrustLogger\n\n\tSpacer // The `state migrate` command logs empty lines to space-out different sections of human-readable output\n}\n\nfunc NewStateMigrate(viewType arguments.ViewType, view *View) StateMigrate {\n\tswitch viewType {\n\tcase arguments.ViewHuman:\n\t\treturn &StateMigrateHuman{view: view}\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"unsupported view type: %s\", viewType))\n\t}\n}\n\nvar (\n\t_ StateMigrate                  = (*StateMigrateHuman)(nil)\n\t_ ProviderInstallationLogger    = (*StateMigrateHuman)(nil)\n\t_ StateStoreProviderTrustLogger = (*StateMigrateHuman)(nil)\n\t_ Spacer                        = (*StateMigrateHuman)(nil)\n)\n\ntype StateMigrateHuman struct {\n\tview *View\n}\n\nfunc (s *StateMigrateHuman) Diagnostics(diags tfdiags.Diagnostics) {\n\ts.view.Diagnostics(diags)\n}\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/views/state_migrate.go#L69-L105","documentation":"NewStateMigrate (internal/command/views/state_migrate.go:81) switches over arguments.ViewType but ONLY implements ViewHuman; everything else panics 'unsupported view type: %s'. This is reachable because ParseStateMigrate (internal/command/arguments/state_migrate.go:128-132) accepts -json and sets ViewJSON when combined with -input=false.","triggerScenarios":"Running 'terraform state migrate -input=false -json ...' — the argument parser sets migrate.ViewType = ViewJSON, the conflicting-flags guard only rejects -json when -input=true, so ViewJSON reaches NewStateMigrate and hits the default panic.","commonSituations":"Automation/CI pipelines that pass -json for machine-readable output on every command including 'state migrate'; wrapping tooling that uniformly adds -input=false -json to non-interactive Terraform runs.","solutions":["Do not pass -json to 'terraform state migrate'; this command has no JSON view implementation, so drop the flag (keep -input=false for automation).","Until upstream implements StateMigrateJSON, have your wrapper skip or special-case -json for this subcommand.","Upstream fix: either implement the JSON view (add a case for arguments.ViewJSON) or reject -json during ParseStateMigrate so users get a clean diagnostic instead of a panic.","Pin/avoid the version that exposes this latent bug if your automation cannot be adjusted."],"exampleFix":"// before\nfunc NewStateMigrate(viewType arguments.ViewType, view *View) StateMigrate {\n    switch viewType {\n    case arguments.ViewHuman:\n        return &StateMigrateHuman{view: view}\n    default:\n        panic(fmt.Sprintf(\"unsupported view type: %s\", viewType))\n    }\n}\n\n// after (reject the unsupported flag at parse time)\n// in arguments/state_migrate.go:\nif json {\n    diags = diags.Append(tfdiags.Sourceless(tfdiags.Error,\n        \"Unsupported flag\",\n        \"-json is not supported by 'state migrate'\"))\n}","handlingStrategy":"validation","validationCode":"// In automation wrappers, do not forward -json to 'state migrate'.\nfunc buildStateMigrateArgs(wantJSON bool) []string {\n    args := []string{\"state\", \"migrate\", \"-input=false\"}\n    // state migrate has NO JSON view; omit -json to avoid the panic.\n    _ = wantJSON\n    return args\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not pass -json to 'terraform state migrate' — it is accepted by the parser but unsupported by the view and crashes the process.","In automation that uniformly applies -input=false -json, special-case 'state migrate' to drop -json.","Track upstream: once StateMigrateJSON is implemented (or -json is rejected at parse time), the workaround can be removed."],"tags":["panic","view-type","state-migrate","json-flag","bug","automation"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}