{"record":{"id":"59cd10337216cfb4","repo":"roboflow/supervision","slug":"max-line-length-must-be-a-positive-integer","errorCode":null,"errorMessage":"max_line_length must be a positive integer","messagePattern":"max_line_length must be a positive integer","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/annotators/utils.py","lineNumber":192,"sourceCode":"    Args:\n        text: The text (or object) to wrap.\n        max_line_length: Maximum width for each wrapped line.\n\n    Returns:\n        Wrapped lines.\n    \"\"\"\n\n    if not text:\n        return [\"\"]\n\n    if not isinstance(text, str):\n        text = str(text)\n\n    if max_line_length is None:\n        return text.splitlines() or [\"\"]\n\n    if max_line_length <= 0:\n        raise ValueError(\"max_line_length must be a positive integer\")\n\n    paragraphs = text.split(\"\\n\")\n    all_lines: list[str] = []\n\n    for paragraph in paragraphs:\n        if paragraph == \"\":\n            all_lines.append(\"\")\n            continue\n\n        wrapped = textwrap.wrap(\n            paragraph,\n            width=max_line_length,\n            break_long_words=True,\n            replace_whitespace=False,\n            drop_whitespace=True,\n        )\n\n        all_lines.extend(wrapped or [\"\"])","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/annotators/utils.py#L174-L210","documentation":"Raised by the text-wrapping helper in supervision.annotators.utils (used for label text) when max_line_length is set but is <= 0. The value is passed to textwrap.wrap as a width, which requires a positive integer; supervision validates it first so the failure names the right parameter instead of surfacing from textwrap internals.","triggerScenarios":"Constructing a LabelAnnotator (or calling the wrap helper) with text_scale/thickness-derived max_line_length that computes to 0 or negative on tiny values; passing max_line_length=0 hoping to disable wrapping; deriving the value from image width where a 0-width input sneaks in.","commonSituations":"Auto-scaling label sizes for very small images (e.g. 32px thumbnails) where int(scale * width) rounds to 0; configuration arithmetic like max_line_length = width // 100 with width < 100; users assuming 0 or -1 means 'unlimited'.","solutions":["Pass None instead of 0 to disable wrapping entirely.","Clamp derived values: max_line_length=max(1, computed).","Validate config before constructing annotators if the value comes from user input.","For tiny images, skip labels or use a fixed minimum like 8 characters."],"exampleFix":"// before\nmll = image_width // 100  # 0 for 80px image\nlabel_annotator = sv.LabelAnnotator(... )\nwrap(text, max_line_length=mll)\n\n// after\nmll = max(8, image_width // 100)\nwrap(text, max_line_length=mll)","handlingStrategy":"validation","validationCode":"if max_line_length is not None:\n    max_line_length = max(1, int(max_line_length))\n\n# or disable wrapping entirely\nwrapped = wrap(text, max_line_length=None)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use None to disable wrapping, never 0 or -1.","Clamp size-derived layout values with max(1, value)."],"tags":["annotators","validation","text-wrapping","configuration"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}