chocolatey/choco · error · ApplicationException
A Rule Name (-n|--name) is required when getting information
Error message
A Rule Name (-n|--name) is required when getting information for a specific rule.
What it means
Thrown by ChocolateyRuleCommand.Validate when the subcommand is 'get' and no --name (-n) was provided. The get operation requires a specific rule to look up, so a name is mandatory. Without it, the command has no target rule to display.
Source
Thrown at src/chocolatey/infrastructure.app/commands/ChocolateyRuleCommand.cs:137
OutputRules("Information/Suggestion", config, implementedRules.Where(r => r.Severity == RuleType.Information).ToList());
OutputRules("Note", config, implementedRules.Where(r => r.Severity == RuleType.Note).ToList());
OutputRules("Disabled", config, implementedRules.Where(r => r.Severity == RuleType.None).ToList());
}
public virtual void Validate(ChocolateyConfiguration configuration)
{
switch (configuration.RuleCommand.Command)
{
case "list":
if (!string.IsNullOrEmpty(configuration.RuleCommand.Name))
{
throw new ApplicationException("A Rule Name (-n|--name) should not be specified when listing all validation rules.");
}
break;
case "get":
if (string.IsNullOrEmpty(configuration.RuleCommand.Name))
{
throw new ApplicationException("A Rule Name (-n|--name) is required when getting information for a specific rule.");
}
break;
default:
this.Log().Warn("Unknown command '{0}'. Setting to list.", configuration.RuleCommand.Command);
configuration.RuleCommand.Command = "list";
Validate(configuration);
break;
}
}
protected override string GetCommandDescription(CommandForAttribute attribute, ChocolateyConfiguration configuration)
{
return @"Retrieve information about what rule validations are implemented by Chocolatey CLI.";
}
protected override IEnumerable<string> GetCommandExamples(CommandForAttribute[] attributes, ChocolateyConfiguration configuration)
{
View on GitHub (pinned to 0d5abdd10c)
Solutions
- Add the required --name flag: 'choco rule get --name=<rule-id>'.
- Run 'choco rule list' first to discover available rule ids.
- If you want to list all rules, use 'choco rule list' instead.
Example fix
// before choco rule get // after choco rule get --name="CHOCO0001"
Defensive patterns
Strategy: validation
Validate before calling
// Ensure --name is provided for 'get'
if (subcommand == "get" && string.IsNullOrWhiteSpace(ruleName))
{
Console.Error.WriteLine("'choco rule get' requires --name=<rule-id>. Run 'choco rule list' to see options.");
} Prevention
- Always provide --name with 'choco rule get'.
- Use 'choco rule list' when you want all rules.
When it happens
Trigger: Running 'choco rule get' with no --name argument. The switch case 'get' checks if configuration.RuleCommand.Name is null or empty and throws.
Common situations: User runs 'choco rule get' expecting a full listing (that is what 'list' does) without specifying which rule to get. Or the --name flag was omitted by mistake in a script.
Related errors
- When specifying the subcommand '{0}', you must also specify
- No rule with the name {0} could be found.
- A Rule Name (-n|--name) should not be specified when listing
- When specifying the subcommand '{0}', you must also specify
- When specifying the subcommand '{0}', you must also specify
AI-assisted analysis of chocolatey/choco@0d5abdd10c (2026-08-13).
Data as JSON: /api/errors/124dcefc910fbbbb.
Report an issue: GitHub.