{"record":{"id":"cbb64010613c51bc","repo":"hashicorp/terraform","slug":"unexpected-empty-message-for-init-message-code-s","errorCode":null,"errorMessage":"unexpected empty message for init message code: %s","messagePattern":"unexpected empty message for init message code: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/views/init.go","lineNumber":227,"sourceCode":"// prints the formatted message to the stdout stream.\nfunc (v *InitHuman) print(message string) {\n\tmessage = v.view.colorize.Color(strings.TrimSpace(message))\n\tv.view.streams.Println(message)\n}\n\n// prepareMessage retrieves a message template matching the InitMessageCode and\n// returns a formatted string made using the template and param argument(s).\n//\n// As this is implemented on InitHuman the human message template is used.\nfunc (v *InitHuman) prepareMessage(messageCode InitMessageCode, params ...any) string {\n\tmessage, ok := MessageRegistry[messageCode]\n\tif !ok {\n\t\t// display the message code as fallback if not found in the message registry\n\t\treturn string(messageCode)\n\t}\n\n\tif message.HumanValue == \"\" {\n\t\tpanic(\"unexpected empty message for init message code: \" + string(messageCode))\n\t}\n\n\treturn fmt.Sprintf(message.HumanValue, params...)\n}\n\n// The InitJSON implementation renders streaming JSON logs, suitable for\n// integrating with other software.\ntype InitJSON struct {\n\tview *JSONView\n}\n\nvar (\n\t_ Init                       = (*InitJSON)(nil)\n\t_ ProviderInstallationLogger = (*InitJSON)(nil)\n)\n\nfunc (v *InitJSON) Diagnostics(diags tfdiags.Diagnostics) {\n\tv.view.Diagnostics(diags)","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/views/init.go#L209-L245","documentation":"This panic fires in InitHuman.prepareMessage when an InitMessageCode resolves to a MessageRegistry entry whose HumanValue is the empty string. The registry must have a human-readable template for every code, so an empty HumanValue means the registry was extended with a code but no human text.","triggerScenarios":"`terraform init` (human output) emits a registered InitMessageCode whose MessageRegistry entry has HumanValue=\"\". Reached when a maintainer adds a code to the InitMessageCode type and a registry row, but leaves HumanValue blank, and init then tries to display it.","commonSituations":"A maintainer adds a new init message code and forgets to fill in (or accidentally empties) the HumanValue field. Triggered the first time init renders that message during a normal `terraform init`.","solutions":["Search MessageRegistry in views/init.go for the code printed in the panic; fill in a non-empty HumanValue template.","Add a test that iterates all InitMessageCode values and asserts MessageRegistry[code].HumanValue != \"\".","If the code should not have a human form, do not register it (or restructure so prepareMessage is never called for it)."],"exampleFix":"// before\nMessageRegistry[InitSomeNewCode] = InitMessage{\n  HumanValue: \"\",\n  JSONValue:  \"some json template\",\n}\n// after\nMessageRegistry[InitSomeNewCode] = InitMessage{\n  HumanValue: \"Initializing some new thing...\",\n  JSONValue:  \"some json template\",\n}","handlingStrategy":"validation","validationCode":"// Validate the registry on init.\nfor code, msg := range MessageRegistry {\n  if msg.HumanValue == \"\" {\n    panic(\"registry missing HumanValue for \" + string(code)) // fail fast at boot\n  }\n}","typeGuard":"// n/a — string emptiness check","tryCatchPattern":null,"preventionTips":["Add an init() or test that asserts MessageRegistry[code].HumanValue != \"\" for every code.","Code-review new InitMessageCode additions for both HumanValue and JSONValue fields.","Treat the registry as a typed struct so omitted fields surface at compile time."],"tags":["terraform-cli","views","init","panic","invariant","message-registry"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}