{"record":{"id":"d638fa4859a9fe52","repo":"chocolatey/choco","slug":"you-must-specify-source-to-remove-an-api-key","errorCode":null,"errorMessage":"You must specify 'source' to remove an API key.","messagePattern":"You must specify 'source' to remove an API key\\.","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/commands/ChocolateyApiKeyCommand.cs","lineNumber":93,"sourceCode":"                }\r\n                else if (!string.IsNullOrWhiteSpace(configuration.ApiKeyCommand.Key))\r\n                {\r\n                    this.Log().Warn(\"API key provided. Setting command to add.\");\r\n                    command = ApiKeyCommandType.Add;\r\n                }\r\n            }\r\n\r\n            configuration.ApiKeyCommand.Command = command;\r\n        }\r\n\r\n        public virtual void Validate(ChocolateyConfiguration configuration)\r\n        {\r\n            switch (configuration.ApiKeyCommand.Command)\r\n            {\r\n                case ApiKeyCommandType.Remove:\r\n                    if (string.IsNullOrWhiteSpace(configuration.Sources))\r\n                    {\r\n                        throw new ApplicationException(\"You must specify 'source' to remove an API key.\");\r\n                    }\r\n\r\n                    break;\r\n                case ApiKeyCommandType.Add:\r\n                    if (string.IsNullOrWhiteSpace(configuration.Sources) || string.IsNullOrWhiteSpace(configuration.ApiKeyCommand.Key))\r\n                    {\r\n                        throw new ApplicationException(\"You must specify both 'source' and 'key' to set an API key.\");\r\n                    }\r\n\r\n                    break;\r\n            }\r\n        }\r\n\r\n        public virtual void HelpMessage(ChocolateyConfiguration configuration)\r\n        {\r\n            this.Log().Info(ChocolateyLoggers.Important, \"ApiKey Command\");\r\n            this.Log().Info(@\"\r\nThis lists API keys that are set or sets an api key for a particular\r","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/commands/ChocolateyApiKeyCommand.cs#L75-L111","documentation":"Validate() requires a source when removing an API key, because removal targets a specific source. With ApiKeyCommand.Remove and a blank configuration.Sources it throws, telling the user to specify 'source'.","triggerScenarios":"Running 'choco apikey remove' (or 'setapikey remove') without -s/--source, so configuration.Sources is null/whitespace.","commonSituations":"Forgetting the -s flag on removal; assuming remove works on all keys at once; copy-paste from an add example that dropped the source.","solutions":["Supply the source: 'choco apikey remove -s https://feed'.","Confirm the exact source string with 'choco apikey list' first so the name matches the stored entry.","Quote URLs that contain special characters."],"exampleFix":"# before\nchoco apikey remove\n\n# after\nchoco apikey remove -s https://push.chocolatey.org/","handlingStrategy":"validation","validationCode":"// Ensure a source is present before issuing a remove.\nif (verb == \"remove\" && string.IsNullOrWhiteSpace(source))\n{\n    throw new InvalidOperationException(\"apikey remove requires -s <source>\");\n}\nRunChoco($\"apikey remove -s \\\"{source}\\\"\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["List keys first ('choco apikey list') to copy the exact source string for removal.","Quote URLs; treat an empty source as a hard error in wrappers."],"tags":["apikey","remove","source","validation"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}