hashicorp/terraform · critical
(*StateMigrateHuman)LogStateMigrationErrored: called incorre
Error message
(*StateMigrateHuman)LogStateMigrationErrored: called incorrectly with unknown failure mode : %q
What it means
StateMigrateHuman.LogStateMigrationErrored (internal/command/views/state_migrate.go:115) switches over the internal stateMigrationFailureMode string enum (DuringMigration, DuringLockfile, DuringWorkDirStateUpdate) to pick a human message. Any other value panics with the method-qualified message. It is an exhaustive switch over a private string enum.
Source
Thrown at internal/command/views/state_migrate.go:127
}
func (s *StateMigrateHuman) LogStateMigrationComplete() {
// no-op in human view
}
func (s *StateMigrateHuman) LogStateMigrationErrored(failMode stateMigrationFailureMode, source, destination string) {
// The JSON object describes slightly different failures that led to an error.
// So different messages are be logged depending which happened.
var msg string
switch failMode {
case DuringMigration:
// migration itself failed
msg = fmt.Sprintf(StateMigrationFailureMessage, source, destination)
case DuringLockfile, DuringWorkDirStateUpdate:
// migration succeeded by updates in the working directory failed
msg = fmt.Sprintf(StateMigrationPostStepsInterruptedMessage, source, destination)
default:
panic(fmt.Sprintf("(*StateMigrateHuman)LogStateMigrationErrored: called incorrectly with unknown failure mode : %q", failMode))
}
s.log(msg)
}
func (s *StateMigrateHuman) LogMigrationSourceInitializationStart() {
// no-op in human view
}
func (s *StateMigrateHuman) LogMigrationSourceInitializationComplete() {
// no-op in human view
}
func (s *StateMigrateHuman) LogMigrationDestinationInitializationStart() {
// no-op in human view
}
func (s *StateMigrateHuman) LogMigrationDestinationInitializationComplete() {View on GitHub (pinned to d32a084675)
Solutions
- When adding a new stateMigrationFailureMode constant, update LogStateMigrationErrored (and its JSON counterpart) in the same change.
- Audit every caller of LogStateMigrationErrored to ensure only the three defined constants are passed.
- Add a compile-time or test-time exhaustive check over the enum to prevent missing branches.
- As an end user this indicates an internal Terraform bug — report it with the migration command that failed.
Defensive patterns
Strategy: validation
Validate before calling
// Exhaustively validate the failure mode before calling the logger.
func validFailureMode(m stateMigrationFailureMode) bool {
switch m {
case DuringMigration, DuringLockfile, DuringWorkDirStateUpdate:
return true
}
return false
}
if !validFailureMode(failMode) {
return fmt.Errorf("invalid state migration failure mode %q", failMode)
} Prevention
- When extending stateMigrationFailureMode, update every switch (human + JSON views) in the same commit.
- Centralise failure-mode construction in one factory so callers cannot invent ad-hoc values.
- Add an exhaustive test over the enum through both view implementations.
When it happens
Trigger: A caller passes a stateMigrationFailureMode value that is not one of the three defined constants — e.g. an empty/uninitialized value, or a new failure mode added to the enum without updating this switch.
Common situations: Extending the state-migration failure taxonomy with a new mode and forgetting to add the human-readable branch; a nil/garbage failure mode produced by a regression in the migration error-handling path.
Related errors
- missing message for InstallingProviderMessage init message c
- unrecognized test progress: %s
- unrecognized status: %s
- unknown view type %v
- unknown view type %v
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/2cd74e1f95d3aba5.
Report an issue: GitHub.