{"record":{"id":"fa4be761ce112f3c","repo":"OpenBMB/ChatDev","slug":"max-results-must-be-positive","errorCode":null,"errorMessage":"max_results must be positive","messagePattern":"max_results must be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"functions/function_calling/file.py","lineNumber":732,"sourceCode":"        Optional[Sequence[str]],\n        ParamMeta(description=\"Restrict search to these glob patterns\"),\n    ] = None,\n    exclude_globs: Annotated[\n        Optional[Sequence[str]],\n        ParamMeta(description=\"Glob patterns to exclude\"),\n    ] = None,\n    use_regex: Annotated[bool, ParamMeta(description=\"Treat pattern as regex\")]=True,\n    case_sensitive: Annotated[bool, ParamMeta(description=\"Match case when True\")]=False,\n    max_results: Annotated[int, ParamMeta(description=\"Stop after this many matches\")]=200,\n    before_context: Annotated[int, ParamMeta(description=\"Lines to include before match\")]=2,\n    after_context: Annotated[int, ParamMeta(description=\"Lines to include after match\")]=2,\n    include_hidden: Annotated[bool, ParamMeta(description=\"Search hidden files/folders\")]=False,\n    _context: Dict[str, Any] | None = None,\n) -> Dict[str, Any]:\n    \"\"\"Search workspace files and return structured matches.\"\"\"\n\n    if max_results <= 0:\n        raise ValueError(\"max_results must be positive\")\n\n    ctx = FileToolContext(_context)\n    include_patterns = _normalize_globs(globs) or [\"**/*\"]\n    exclude_patterns = _normalize_globs(exclude_globs)\n\n    matches: List[Dict[str, Any]] = []\n    searched_files = 0\n    compiled_regex: Optional[re.Pattern[str]] = None\n    literal = pattern if case_sensitive else pattern.lower()\n    if use_regex:\n        flags = re.MULTILINE\n        if not case_sensitive:\n            flags |= re.IGNORECASE\n        compiled_regex = re.compile(pattern, flags)\n\n    for candidate in _iter_candidate_files(\n        ctx.workspace_root,\n        include_patterns,","sourceCodeStart":714,"sourceCodeEnd":750,"githubUrl":"https://github.com/OpenBMB/ChatDev/blob/4fb2db0ea90375ce1059f44fe03ffbd191a7a169/functions/function_calling/file.py#L714-L750","documentation":"search_in_files validates its max_results parameter up front and rejects non-positive values. Any value <= 0 (0, negative counts, or a value that coerces to <= 0) raises ValueError before any scanning starts. This is a defensive guard so the result cap is always meaningful.","triggerScenarios":"Calling search_in_files(..., max_results=0) or a negative number; computing max_results from a configurable page size or subtraction that yields 0; passing a falsy default from an unset config value.","commonSituations":"Pagination code where limit = page_size * 0 or user-supplied limit defaults to 0; config-driven search where a missing setting is treated as 0; CLI wrappers mapping --max-results=0 as 'unlimited' (not supported here).","solutions":["Pass a positive integer such as 50 or 100 for max_results","If you intended 'unlimited', pass a large positive cap instead of 0","Fix upstream computation (page size, config default) so it cannot produce 0","Add a guard clamping max_results to at least 1 before calling"],"exampleFix":"# before\nsearch_in_files(pattern=\"TODO\", max_results=0)\n# after\nsearch_in_files(pattern=\"TODO\", max_results=100)","handlingStrategy":"validation","validationCode":"max_results = max(1, int(max_results or DEFAULT_CAP))\nsearch_in_files(pattern=p, max_results=max_results)","typeGuard":"def is_positive_int(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool) and v > 0","tryCatchPattern":"try:\n    search_in_files(pattern=p, max_results=n)\nexcept ValueError as e:\n    if \"max_results\" in str(e):\n        n = 100\n        search_in_files(pattern=p, max_results=n)\n    else:\n        raise","preventionTips":["Default max_results to a sane positive constant (50/100)","Clamp user-supplied limits to >= 1 at the boundary","Treat 0 as 'use default', never pass it through"],"tags":["validation","search","argument-error"],"backgroundTag":"invalid-argument-value","analyzedSha":"4fb2db0ea90375ce1059f44fe03ffbd191a7a169","analyzedAt":"2026-08-27T14:35:29.622Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}