chocolatey/choco · error · ApplicationException

A Rule Name (-n|--name) should not be specified when listing

Error message

A Rule Name (-n|--name) should not be specified when listing all validation rules.

What it means

Thrown by ChocolateyRuleCommand.Validate when the subcommand is 'list' and a --name (-n) was also specified. Listing all rules does not filter by name — it shows every rule — so providing a name is contradictory and rejected to prevent confusion. The switch statement on RuleCommand.Command handles 'list' and 'get' cases separately.

Source

Thrown at src/chocolatey/infrastructure.app/commands/ChocolateyRuleCommand.cs:131

            {
                this.Log().Info(ChocolateyLoggers.Important, "Implemented Package Rules");
            }

            OutputRules("Error/Required", config, implementedRules.Where(r => r.Severity == RuleType.Error).ToList());
            OutputRules("Warning/Guideline", config, implementedRules.Where(r => r.Severity == RuleType.Warning).ToList());
            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)

View on GitHub (pinned to 0d5abdd10c)

Solutions

  1. Remove the --name flag when listing all rules: 'choco rule list'.
  2. If you want details for a specific rule, use the 'get' subcommand instead: 'choco rule get --name=<id>'.

Example fix

// before
choco rule list --name="CHOCO0001"
// after
choco rule get --name="CHOCO0001"
// or simply
choco rule list
Defensive patterns

Strategy: validation

Validate before calling

// Do not pass --name with 'list'
if (subcommand == "list" && !string.IsNullOrWhiteSpace(ruleName))
{
    Console.Error.WriteLine("Do not pass --name with 'choco rule list'. Use 'get' for a specific rule.");
}

Prevention

When it happens

Trigger: Running 'choco rule list --name=<something>' or 'choco rule list -n <something>'. The list subcommand is mutually exclusive with the name option.

Common situations: User mistakenly adds --name when intending to see all rules, or a script defaults to passing --name even for listing. The user may have intended 'get' instead of 'list'.

Related errors


AI-assisted analysis of chocolatey/choco@0d5abdd10c (2026-08-13). Data as JSON: /api/errors/2d02345a324f08ea. Report an issue: GitHub.