{"record":{"id":"6e14fdc1b2c517d5","repo":"caddyserver/caddy","slug":"command-short-string-is-required","errorCode":null,"errorMessage":"command short string is required","messagePattern":"command short string is required","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"cmd/commands.go","lineNumber":589,"sourceCode":"//   - hyphen cannot be adjacent to another hyphen\n//\n// This function panics if the name is already registered,\n// if the name does not meet the described format, or if\n// any of the fields are missing from cmd.\n//\n// This function should be used in init().\nfunc RegisterCommand(cmd Command) {\n\tcommandsMu.Lock()\n\tdefer commandsMu.Unlock()\n\n\tif cmd.Name == \"\" {\n\t\tpanic(\"command name is required\")\n\t}\n\tif cmd.Func == nil && cmd.CobraFunc == nil {\n\t\tpanic(\"command function missing\")\n\t}\n\tif cmd.Short == \"\" {\n\t\tpanic(\"command short string is required\")\n\t}\n\tif _, exists := commands[cmd.Name]; exists {\n\t\tpanic(\"command already registered: \" + cmd.Name)\n\t}\n\tif !commandNameRegex.MatchString(cmd.Name) {\n\t\tpanic(\"invalid command name\")\n\t}\n\tdefaultFactory.Use(func(rootCmd *cobra.Command) {\n\t\trootCmd.AddCommand(caddyCmdToCobra(cmd))\n\t})\n\tcommands[cmd.Name] = cmd\n}\n\nvar commandNameRegex = regexp.MustCompile(`^[a-z0-9]$|^([a-z0-9]+-?[a-z0-9]*)+[a-z0-9]$`)\n","sourceCodeStart":571,"sourceCodeEnd":604,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/cmd/commands.go#L571-L604","documentation":"RegisterCommand panics when a Command registered from a plugin lacks a Short description. Short is what caddy help and CLI listings display; an empty one means the command was incompletely constructed, which is a programmer error in the plugin, not a runtime condition, hence a panic at init time.","triggerScenarios":"A plugin's init() calls caddy.RegisterCommand(caddy.Command{Name: \"foo\", Func: ...}) without setting Short; the panic occurs at process start or during tests that import the plugin.","commonSituations":"Plugin development where the author filled Name and Func but omitted Short; refactors that drop the field; copy-paste of a minimal command skeleton.","solutions":["Add a Short string to the Command struct before registering","If embedding Caddy as a library, recover the init panic and report which plugin is at fault (check the registration order)"],"exampleFix":"// before\ncaddy.RegisterCommand(caddy.Command{\n    Name: \"cache-clear\",\n    Func: clearCache,\n})\n\n// after\ncaddy.RegisterCommand(caddy.Command{\n    Name:  \"cache-clear\",\n    Usage: \"\",\n    Short: \"Clear the HTTP cache\",\n    Func:  clearCache,\n})","handlingStrategy":"validation","validationCode":"if cmd.Short == \"\" {\n    return fmt.Errorf(\"command %q needs a Short description\", cmd.Name)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fill Name, Short, and Func in every RegisterCommand call","Write a unit test that registers all your plugin commands to catch panics at test time"],"tags":["caddy","cli","plugin","panic"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}