{"record":{"id":"b1ac0a8d9eb9dc08","repo":"langchain-ai/langchain","slug":"char-should-be-a-single-character","errorCode":null,"errorMessage":"char should be a single character","messagePattern":"char should be a single character","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"libs/core/langchain_core/runnables/graph_ascii.py","lineNumber":107,"sourceCode":"\n    def point(self, x: int, y: int, char: str) -> None:\n        \"\"\"Create a point on ASCII canvas.\n\n        Args:\n            x: x coordinate. Should be `>= 0` and `<` number of columns in\n                the canvas.\n            y: y coordinate. Should be `>= 0` an `<` number of lines in the\n                canvas.\n            char: character to place in the specified point on the\n                canvas.\n\n        Raises:\n            ValueError: if char is not a single character or if\n                coordinates are out of bounds.\n        \"\"\"\n        if len(char) != 1:\n            msg = \"char should be a single character\"\n            raise ValueError(msg)\n        if x >= self.cols or x < 0:\n            msg = \"x should be >= 0 and < number of columns\"\n            raise ValueError(msg)\n        if y >= self.lines or y < 0:\n            msg = \"y should be >= 0 and < number of lines\"\n            raise ValueError(msg)\n\n        self.canvas[y][x] = char\n\n    def line(self, x0: int, y0: int, x1: int, y1: int, char: str) -> None:\n        \"\"\"Create a line on ASCII canvas.\n\n        Args:\n            x0: x coordinate where the line should start.\n            y0: y coordinate where the line should start.\n            x1: x coordinate where the line should end.\n            y1: y coordinate where the line should end.\n            char: character to draw the line with.","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/runnables/graph_ascii.py#L89-L125","documentation":"`AsciiCanvas.draw_on` places one character at a coordinate, so `char` must be a string of length exactly 1. Passing a multi-character string (or empty string) has no single grid cell to occupy and raises `ValueError: char should be a single character`.","triggerScenarios":"Calling `canvas.draw_on(x, y, \"->\")`, `draw_on(x, y, \"\")`, or passing a label/arrow of length > 1; customizing `DrawGraph` (which itself draws arrow chars like `>` one cell at a time) with multi-char glyphs such as `\"=>\"` or emoji.","commonSituations":"Extending graph ASCII rendering with custom arrowheads or markers; drawing edge labels directly with `draw_on` instead of looping per character; passing a character variable that defaults to an empty string.","solutions":["Draw multi-character content one character at a time: `for i, c in enumerate(s): canvas.draw_on(x + i, y, c)`.","Use a single glyph (e.g. `\">\"`, `\"*\"`) where one cell is expected.","Guard with `if len(char) != 1: raise/handle` before calling when char comes from user config."],"exampleFix":"# before\ncanvas.draw_on(x, y, \"->\")\n\n# after\nfor i, ch in enumerate(\"->\"):\n    canvas.draw_on(x + i, y, ch)","handlingStrategy":"validation","validationCode":"assert isinstance(char, str) and len(char) == 1\ncanvas.draw_on(x, y, char)","typeGuard":"from typing import TypeGuard\n\ndef is_single_char(s: object) -> TypeGuard[str]:\n    return isinstance(s, str) and len(s) == 1","tryCatchPattern":null,"preventionTips":["Draw multi-char strings one character per cell.","Use single glyphs for arrows/markers.","Validate config-supplied glyphs before rendering."],"tags":["graph","ascii-art","value-error","visualization","langchain-core"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}