caddyserver/caddy · error

unrecognized shell: %s

Error message

unrecognized shell: %s

What it means

The 'completion' command's switch over the single shell argument fell through to default. Bash, zsh, fish, and powershell are the supported shells; anything else reaches this error. Note cobra's OnlyValidArgs normally intercepts invalid values first, so hitting this message means validation was bypassed (custom build, older cobra, or direct invocation of the RunE).

Source

Thrown at cmd/commands.go:545

	  PS> %[1]s completion powershell > %[1]s.ps1
	  # and source this file from your PowerShell profile.
	`, rootCmd.Root().Name()),
			CobraFunc: func(cmd *cobra.Command) {
				cmd.DisableFlagsInUseLine = true
				cmd.ValidArgs = []string{"bash", "zsh", "fish", "powershell"}
				cmd.Args = cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs)
				cmd.RunE = func(cmd *cobra.Command, args []string) error {
					switch args[0] {
					case "bash":
						return cmd.Root().GenBashCompletion(os.Stdout)
					case "zsh":
						return cmd.Root().GenZshCompletion(os.Stdout)
					case "fish":
						return cmd.Root().GenFishCompletion(os.Stdout, true)
					case "powershell":
						return cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
					default:
						return fmt.Errorf("unrecognized shell: %s", args[0])
					}
				}
			},
		}

		rootCmd.AddCommand(caddyCmdToCobra(manpageCommand))
		rootCmd.AddCommand(caddyCmdToCobra(completionCommand))

		// add manpage and completion commands to the map of
		// available commands, because they're not registered
		// through RegisterCommand.
		commandsMu.Lock()
		commands[manpageCommand.Name] = manpageCommand
		commands[completionCommand.Name] = completionCommand
		commandsMu.Unlock()
	})
}

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Use one of: bash, zsh, fish, powershell
  2. Check caddy completion --help for the exact accepted values

Example fix

# before
caddy completion sh

# after
caddy completion bash
Defensive patterns

Strategy: validation

Validate before calling

shell := args[0]
valid := map[string]bool{"bash": true, "zsh": true, "fish": true, "powershell": true}
if !valid[shell] { return fmt.Errorf("unsupported shell %q; use bash|zsh|fish|powershell", shell) }

Type guard

func isValidShell(s string) bool { switch s { case "bash", "zsh", "fish", "powershell": return true }; return false }

Prevention

When it happens

Trigger: Running 'caddy completion tcsh' or 'caddy completion sh'; a typo like 'caddy completion bahs'.

Common situations: Users expecting a generic POSIX completion output; scripts hardcoding a shell name not in the supported set.

Related errors


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/c5f44ea1e4e41309. Report an issue: GitHub.