{"record":{"id":"c2da4d99dbd4ccbf","repo":"iOfficeAI/OfficeCLI","slug":"criteria-colid-op-requires-a-numeric-value-got","errorCode":null,"errorMessage":"criteria{colId}.{op} requires a numeric value, got: '{rawVal}'","messagePattern":"criteria(.+?)\\.(.+?) requires a numeric value, got: '(.+?)'","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs","lineNumber":891,"sourceCode":"                            customEntries.Add((FilterOperatorValues.LessThanOrEqual, hi));\n                            customFilterAnd = true;\n                        }\n                        else\n                        {\n                            // notBetween = lt lo OR gt hi (Excel default OR)\n                            customEntries.Add((FilterOperatorValues.LessThan, lo));\n                            customEntries.Add((FilterOperatorValues.GreaterThan, hi));\n                        }\n                        break;\n                    }\n                    case \"top\":\n                    case \"toppercent\":\n                    case \"bottom\":\n                    case \"bottompercent\":\n                    {\n                        if (!double.TryParse(rawVal, System.Globalization.NumberStyles.Any,\n                                System.Globalization.CultureInfo.InvariantCulture, out var topN))\n                            throw new ArgumentException(\n                                $\"criteria{colId}.{op} requires a numeric value, got: '{rawVal}'\");\n                        filterColumn.Top10 = new Top10\n                        {\n                            Top = op == \"top\" || op == \"toppercent\",\n                            Percent = op == \"toppercent\" || op == \"bottompercent\",\n                            Val = topN\n                        };\n                        handledDedicated = true;\n                        break;\n                    }\n                    case \"blanks\":\n                        if (IsTruthy(rawVal))\n                        {\n                            filterColumn.Filters = new Filters { Blank = true };\n                            handledDedicated = true;\n                        }\n                        break;\n                    case \"nonblanks\":","sourceCodeStart":873,"sourceCodeEnd":909,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs#L873-L909","documentation":"Thrown by AddAutoFilter when a Top-N / Bottom-N filter operator (top, topPercent, bottom, bottomPercent) receives a value that is not parseable as a double using InvariantCulture. Excel's <top10> element requires a numeric Val attribute, so a non-numeric string cannot be serialized correctly. The handler validates up front rather than emitting a bad part.","triggerScenarios":"Calling Add with a property like criteria2.top=ten, criteria2.toppercent=, criteria2.bottom=abc, or criteria2.bottompercent=1,5 (comma-decimal in an invariant-culture parse).","commonSituations":"Typing the count as a word, leaving the value empty, or passing a locale-formatted number where the comma is the decimal separator (InvariantCulture expects a dot).","solutions":["Pass a plain numeric value, e.g. criteria2.top=10 or criteria2.toppercent=25.","For percentages use a dot as the decimal separator: criteria2.toppercent=12.5.","Ensure the value is non-empty; an empty string fails the double.TryParse."],"exampleFix":"// before\n--prop criteria2.top=ten\n// after\n--prop criteria2.top=10","handlingStrategy":"validation","validationCode":"// Validate top/bottom filter values parse as invariant-culture doubles before Add.\nstatic bool TryValidateTopN(string op, string rawVal, out string error)\n{\n    error = null;\n    if (op is not (\"top\" or \"toppercent\" or \"bottom\" or \"bottompercent\")) return true;\n    if (!double.TryParse(rawVal, System.Globalization.NumberStyles.Any,\n            System.Globalization.CultureInfo.InvariantCulture, out _))\n    {\n        error = $\"criteria.{op} requires a numeric value, got: '{rawVal}'\";\n        return false;\n    }\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try { handler.Add(path, \"autofilter\", null, props); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"requires a numeric value\"))\n{ /* surface: top/bottom filters need an invariant-culture number */ }","preventionTips":["Always format numbers with InvariantCulture (dot decimal) when building criteria values programmatically.","Reject empty values up front; double.TryParse on empty returns false.","Document that 'toppercent'/'bottompercent' expect a number (count or percent), not a boolean."],"tags":["excel","autofilter","validation","numeric-parsing"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}