{"record":{"id":"a40674cb40781d06","repo":"chocolatey/choco","slug":"the-order-by-clause-0-is-not-recognized-u","errorCode":null,"errorMessage":"The '--order-by' clause '{0}' is not recognized. Use one of the supported clauses:\n '{1}'.","messagePattern":"The '--order-by' clause '(.+?)' is not recognized\\. Use one of the supported clauses:\n '(.+?)'\\.","errorType":"validation","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/commands/ChocolateySearchCommand.cs","lineNumber":125,"sourceCode":"                     option => configuration.ListCommand.IdStartsWith = option != null)\r\n                 .Add(\"order-by=\",\r\n                     \"OrderBy - Sort package results by Id (default), {0}. Available in 2.5.0+.\".FormatWith(string.Join(\", \", Enum.GetNames(typeof(PackageOrder)).Where(n => !n.IsEqualTo(\"Id\")))),\r\n                     option =>\r\n                     {\r\n                        var validOptions = Enum.GetNames(typeof(PackageOrder));\r\n                         var formattedOptions = string.Join(\"', '\", validOptions);\r\n                         var unquotedOption = option.UnquoteSafe();\r\n\r\n                         if (string.IsNullOrWhiteSpace(unquotedOption))\r\n                         {\r\n                             throw new ApplicationException(\r\n                                @\"No '--order-by' clause was provided. Specify one of the supported clauses:\r\n '{0}'.\".FormatWith(formattedOptions));\r\n                         }\r\n\r\n                         if (!Enum.TryParse(unquotedOption, ignoreCase: true, out PackageOrder orderBy))\r\n                         {\r\n                            throw new ApplicationException(\r\n                                @\"The '--order-by' clause '{0}' is not recognized. Use one of the supported clauses:\r\n '{1}'.\".FormatWith(unquotedOption, formattedOptions));\r\n                         }\r\n\r\n                         configuration.ListCommand.OrderBy = orderBy;\r\n                 })\r\n                 .Add(\"order-by-popularity\",\r\n                     \"(Deprecated) OrderByPopularity - Sort package results by popularity. Use '--order-by='Popularity'' instead.\",\r\n                     option =>\r\n                     {\r\n                         if (option != null)\r\n                         {\r\n                             configuration.ListCommand.OrderByPopularity = true;\r\n\r\n                             this.Log().Warn(\r\n                                 @\"'--order-by-popularity' is deprecated and will be removed in a future release.\r\n Use '--order-by='Popularity'' instead.\");\r\n                         }\r","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/commands/ChocolateySearchCommand.cs#L107-L143","documentation":"Thrown during argument parsing for --order-by when the provided value (after unquoting) is non-empty but does not match any PackageOrder enum name via case-insensitive Enum.TryParse. The message lists the valid clause names formatted with quotes for clarity.","triggerScenarios":"Running 'choco search --order-by=<invalid>' where <invalid> is not one of the PackageOrder enum values (e.g. 'choco search --order-by=Date' when no such enum member exists). The Enum.TryParse fails and the error lists valid options.","commonSituations":"User guesses a sort field name that does not exist. Version differences where an option name was renamed. Copying from outdated documentation.","solutions":["Read the error message — it lists all valid options quoted.","Use an exact valid value: 'choco search --order-by=Popularity'.","Run 'choco search --help' to see documented order-by options."],"exampleFix":"// before\nchoco search --order-by=Date\n// after\nchoco search --order-by=Popularity","handlingStrategy":"validation","validationCode":"// Validate order-by is a known enum value\nvar validOptions = Enum.GetNames(typeof(PackageOrder));\nif (!Enum.TryParse<PackageOrder>(orderBy, ignoreCase: true, out _))\n{\n    Console.Error.WriteLine($\"Invalid --order-by '{orderBy}'. Valid: {string.Join(\", \", validOptions)}\");\n}","typeGuard":"static bool IsValidOrderBy(string value) => Enum.TryParse<PackageOrder>(value, ignoreCase: true, out _);","tryCatchPattern":null,"preventionTips":["Check valid PackageOrder enum names before passing --order-by.","Read the error message which lists all valid options."],"tags":["chocolatey","search-command","invalid-value","order-by","enum-parse"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}