{"record":{"id":"47f1f949151985ad","repo":"chocolatey/choco","slug":"when-specifying-the-subcommand-add-you-must-als","errorCode":null,"errorMessage":"When specifying the subcommand 'add', you must also specify --source.","messagePattern":"When specifying the subcommand 'add', you must also specify --source\\.","errorType":"validation","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs","lineNumber":115,"sourceCode":"                    this.Log().Warn(\"Unknown command {0}. Setting to list.\".FormatWith(unparsedCommand));\r\n                }\r\n\r\n                command = SourceCommandType.List;\r\n            }\r\n\r\n            configuration.SourceCommand.Command = command;\r\n        }\r\n\r\n        public virtual void Validate(ChocolateyConfiguration configuration)\r\n        {\r\n            if (configuration.SourceCommand.Command != SourceCommandType.List && string.IsNullOrWhiteSpace(configuration.SourceCommand.Name))\r\n            {\r\n                throw new ApplicationException(\"When specifying the subcommand '{0}', you must also specify --name.\".FormatWith(configuration.SourceCommand.Command.ToStringSafe().ToLower()));\r\n            }\r\n\r\n            if (configuration.SourceCommand.Command == SourceCommandType.Add && string.IsNullOrWhiteSpace(configuration.Sources))\r\n            {\r\n                throw new ApplicationException(\"When specifying the subcommand 'add', you must also specify --source.\");\r\n            }\r\n\r\n            if (!string.IsNullOrWhiteSpace(configuration.SourceCommand.Username) && string.IsNullOrWhiteSpace(configuration.SourceCommand.Password))\r\n            {\r\n                this.Log().Debug(ChocolateyLoggers.LogFileOnly, \"Username '{0}' provided. Asking for password.\".FormatWith(configuration.SourceCommand.Username));\r\n                System.Console.Write(\"User name '{0}' provided. Password: \".FormatWith(configuration.SourceCommand.Username));\r\n                configuration.SourceCommand.Password = InteractivePrompt.GetPassword(configuration.PromptForConfirmation);\r\n            }\r\n        }\r\n\r\n        public virtual void HelpMessage(ChocolateyConfiguration configuration)\r\n        {\r\n            this.Log().Info(ChocolateyLoggers.Important, \"Source Command\");\r\n            this.Log().Info(@\"\r\nChocolatey will allow you to interact with sources.\r\n\");\r\n\r\n            \"chocolatey\".Log().Info(ChocolateyLoggers.Important, \"Usage\");\r","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/commands/ChocolateySourceCommand.cs#L97-L133","documentation":"Thrown by ChocolateySourceCommand.Validate when the subcommand is 'add' and configuration.Sources is null or empty. Adding a source requires both a name (--name) and a source URL (--source). This specific check guards the missing --source case, which is separate from the --name check above it.","triggerScenarios":"Running 'choco source add --name=myfeed' without specifying --source=<url>. The condition: SourceCommand.Command == Add AND configuration.Sources is empty.","commonSituations":"User provides only a name for the new source and forgets the URL. Argument typo where --source is misspelled or misquoted so it is not parsed.","solutions":["Add the --source flag with the feed URL: 'choco source add --name=myfeed --source=\"https://my.feed/nuget\"'.","Ensure the --source value is properly quoted, especially if it contains special characters.","Verify both --name and --source are present before running."],"exampleFix":"// before\nchoco source add --name=\"myfeed\"\n// after\nchoco source add --name=\"myfeed\" --source=\"https://my.feed/nuget\"","handlingStrategy":"validation","validationCode":"// For 'add', ensure --source is provided\nif (sourceSubcommand == \"add\" && string.IsNullOrWhiteSpace(sourceUrl))\n{\n    Console.Error.WriteLine(\"choco source add requires both --name and --source.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide --source=<url> when adding a new source.","Properly quote URLs containing special characters."],"tags":["chocolatey","source-command","missing-argument","add-source"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}