{"record":{"id":"306c6eefcf7e812f","repo":"Textualize/rich","slug":"characters-argument-must-have-a-cell-width-of-at","errorCode":null,"errorMessage":"'characters' argument must have a cell width of at least 1","messagePattern":"'characters' argument must have a cell width of at least 1","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"rich/rule.py","lineNumber":33,"sourceCode":"    Args:\n        title (Union[str, Text], optional): Text to render in the rule. Defaults to \"\".\n        characters (str, optional): Character(s) used to draw the line. Defaults to \"─\".\n        style (StyleType, optional): Style of Rule. Defaults to \"rule.line\".\n        end (str, optional): Character at end of Rule. defaults to \"\\\\\\\\n\"\n        align (str, optional): How to align the title, one of \"left\", \"center\", or \"right\". Defaults to \"center\".\n    \"\"\"\n\n    def __init__(\n        self,\n        title: Union[str, Text] = \"\",\n        *,\n        characters: str = \"─\",\n        style: Union[str, Style] = \"rule.line\",\n        end: str = \"\\n\",\n        align: AlignMethod = \"center\",\n    ) -> None:\n        if cell_len(characters) < 1:\n            raise ValueError(\n                \"'characters' argument must have a cell width of at least 1\"\n            )\n        if align not in (\"left\", \"center\", \"right\"):\n            raise ValueError(\n                f'invalid value for align, expected \"left\", \"center\", \"right\" (not {align!r})'\n            )\n        self.title = title\n        self.characters = characters\n        self.style = style\n        self.end = end\n        self.align = align\n\n    def __repr__(self) -> str:\n        return f\"Rule({self.title!r}, {self.characters!r})\"\n\n    def __rich_console__(\n        self, console: Console, options: ConsoleOptions\n    ) -> RenderResult:","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/Textualize/rich/blob/9d8f9a372cc5916fd4781fec207ced7ddac2f08f/rich/rule.py#L15-L51","documentation":"Rule renders a horizontal line built by repeating its characters= string. rich validates that the string has a display (cell) width of at least 1, measured with cell_len — which understands East Asian wide characters and zero-width joins. A string of only zero-width/combining characters (cell width 0) cannot draw a line, so Rule raises ValueError at construction.","triggerScenarios":"Rule(characters=''), Rule(characters='\\u200b') (zero-width space), Rule(characters='\\u0301') (combining mark), or any sequence whose combined cell width is 0. Note: a string like '──' is fine; the check is width, not count.","commonSituations":"User-configurable separator characters (CLI themes, config files) where an empty string slips through; loading separator settings from YAML/JSON where the value is blank; passing a stripped/normalized string that ended up empty; characters read from a source that lost a zero-width glyph.","solutions":["Default to '─' (U+2500) or pass a real visible character: Rule('Title', characters='=') .","Validate config-supplied separators before use: if not chars or cell_len(chars) < 1: use fallback.","For an invisible divider, use a space-padded character like ' ' plus a style, or render a blank Text instead of a zero-width Rule."],"exampleFix":"# before\nprint(Rule('Header', characters=''))  # ValueError: cell width of at least 1\n\n# after\nchars = cfg.get('rule_chars') or '─'\nprint(Rule('Header', characters=chars))","handlingStrategy":"validation","validationCode":"from rich.cells import cell_len\nchars = cfg.get('rule_chars', '')\nif cell_len(chars) < 1:\n    chars = '─'\nrule = Rule('Title', characters=chars)","typeGuard":"def is_valid_rule_characters(chars: str) -> bool:\n    return isinstance(chars, str) and cell_len(chars) >= 1","tryCatchPattern":null,"preventionTips":["Validate user/config-supplied separator strings with rich.cells.cell_len before constructing Rule.","Treat empty separator config as 'use default' rather than passing it through."],"tags":["rich","rule","validation","cell-width","valueerror"],"backgroundTag":null,"analyzedSha":"9d8f9a372cc5916fd4781fec207ced7ddac2f08f","analyzedAt":"2026-08-15T03:30:11.781Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}