{"record":{"id":"2cd74e1f95d3aba5","repo":"hashicorp/terraform","slug":"statemigratehuman-logstatemigrationerrored-call","errorCode":null,"errorMessage":"(*StateMigrateHuman)LogStateMigrationErrored: called incorrectly with unknown failure mode : %q","messagePattern":"\\(\\*StateMigrateHuman\\)LogStateMigrationErrored: called incorrectly with unknown failure mode : %q","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/views/state_migrate.go","lineNumber":127,"sourceCode":"}\n\nfunc (s *StateMigrateHuman) LogStateMigrationComplete() {\n\t// no-op in human view\n}\n\nfunc (s *StateMigrateHuman) LogStateMigrationErrored(failMode stateMigrationFailureMode, source, destination string) {\n\t// The JSON object describes slightly different failures that led to an error.\n\t// So different messages are be logged depending which happened.\n\tvar msg string\n\tswitch failMode {\n\tcase DuringMigration:\n\t\t// migration itself failed\n\t\tmsg = fmt.Sprintf(StateMigrationFailureMessage, source, destination)\n\tcase DuringLockfile, DuringWorkDirStateUpdate:\n\t\t// migration succeeded by updates in the working directory failed\n\t\tmsg = fmt.Sprintf(StateMigrationPostStepsInterruptedMessage, source, destination)\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"(*StateMigrateHuman)LogStateMigrationErrored: called incorrectly with unknown failure mode : %q\", failMode))\n\t}\n\n\ts.log(msg)\n}\n\nfunc (s *StateMigrateHuman) LogMigrationSourceInitializationStart() {\n\t// no-op in human view\n}\n\nfunc (s *StateMigrateHuman) LogMigrationSourceInitializationComplete() {\n\t// no-op in human view\n}\n\nfunc (s *StateMigrateHuman) LogMigrationDestinationInitializationStart() {\n\t// no-op in human view\n}\n\nfunc (s *StateMigrateHuman) LogMigrationDestinationInitializationComplete() {","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/views/state_migrate.go#L109-L145","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Exhaustively validate the failure mode before calling the logger.\nfunc validFailureMode(m stateMigrationFailureMode) bool {\n    switch m {\n    case DuringMigration, DuringLockfile, DuringWorkDirStateUpdate:\n        return true\n    }\n    return false\n}\nif !validFailureMode(failMode) {\n    return fmt.Errorf(\"invalid state migration failure mode %q\", failMode)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["panic","exhaustive-switch","state-migrate","enum","internal-bug"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}