{"record":{"id":"e9142ffe73104d33","repo":"caddyserver/caddy","slug":"at-least-one-package-name-must-be-specified","errorCode":null,"errorMessage":"at least one package name must be specified","messagePattern":"at least one package name must be specified","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/packagesfuncs.go","lineNumber":70,"sourceCode":"\t// accommodate module paths that have @ in them, but we can only tolerate that if there's also\n\t// a version, otherwise we don't know if it's a version separator or part of the file path\n\tlastVersionSplit := strings.LastIndex(arg, versionSplit)\n\tif lastVersionSplit < 0 {\n\t\tmodule = arg\n\t} else {\n\t\tmodule, version = arg[:lastVersionSplit], arg[lastVersionSplit+1:]\n\t}\n\n\tif module == \"\" {\n\t\terr = fmt.Errorf(\"module name is required\")\n\t}\n\n\treturn module, version, err\n}\n\nfunc cmdAddPackage(fl Flags) (int, error) {\n\tif len(fl.Args()) == 0 {\n\t\treturn caddy.ExitCodeFailedStartup, fmt.Errorf(\"at least one package name must be specified\")\n\t}\n\t_, nonstandard, _, err := getModules()\n\tif err != nil {\n\t\treturn caddy.ExitCodeFailedStartup, fmt.Errorf(\"unable to enumerate installed plugins: %v\", err)\n\t}\n\tpluginPkgs, err := getPluginPackages(nonstandard)\n\tif err != nil {\n\t\treturn caddy.ExitCodeFailedStartup, err\n\t}\n\n\tfor _, arg := range fl.Args() {\n\t\tmodule, version, err := splitModule(arg)\n\t\tif err != nil {\n\t\t\treturn caddy.ExitCodeFailedStartup, fmt.Errorf(\"invalid module name: %v\", err)\n\t\t}\n\t\t// only allow a version to be specified if it's different from the existing version\n\t\tif _, ok := pluginPkgs[module]; ok && (version == \"\" || pluginPkgs[module].Version == version) {\n\t\t\treturn caddy.ExitCodeFailedStartup, fmt.Errorf(\"package is already added\")","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/cmd/packagesfuncs.go#L52-L88","documentation":"`caddy add-package` refuses to run with zero package arguments. At least one module path is required because the command's whole purpose is to add plugins to the current build.","triggerScenarios":"Running `caddy add-package` with no positional args, or with args consumed by flag parsing so that fl.Args() is empty.","commonSituations":"Scripts where the package list variable is empty (`caddy add-package $PLUGINS` with PLUGINS unset), or invoking the command expecting it to be interactive.","solutions":["Pass one or more module paths: `caddy add-package github.com/caddy-dns/cloudflare github.com/mholt/caddy-ratelimit`","In scripts, guard the invocation: `[ -n \"$PLUGINS\" ] && caddy add-package $PLUGINS`"],"exampleFix":"# before\ncaddy add-package\n\n# after\ncaddy add-package github.com/caddy-dns/cloudflare","handlingStrategy":"validation","validationCode":"[ \"$#\" -ge 1 ] || { echo 'usage: caddy add-package <module> [...]'; exit 1; }\ncaddy add-package \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard scripted invocations against empty package lists"],"tags":["caddy","cli","packages","argument-validation"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}