langchain-ai/langchain · warning · ValueError
Canvas dimensions should be > 1
Error message
Canvas dimensions should be > 1
What it means
`AsciiCanvas.__init__` (used by `DrawGraph` to render runnable graphs as ASCII art) requires both `cols` and `lines` to be greater than 1, otherwise there is no drawable area. Violating this raises `ValueError: Canvas dimensions should be > 1`.
Source
Thrown at libs/core/langchain_core/runnables/graph_ascii.py:74
class AsciiCanvas:
"""Class for drawing in ASCII."""
TIMEOUT = 10
def __init__(self, cols: int, lines: int) -> None:
"""Create an ASCII canvas.
Args:
cols: number of columns in the canvas. Should be `> 1`.
lines: number of lines in the canvas. Should be `> 1`.
Raises:
ValueError: if canvas dimensions are invalid.
"""
if cols <= 1 or lines <= 1:
msg = "Canvas dimensions should be > 1"
raise ValueError(msg)
self.cols = cols
self.lines = lines
self.canvas = [[" "] * cols for line in range(lines)]
def draw(self) -> str:
"""Draws ASCII canvas on the screen.
Returns:
The ASCII canvas string.
"""
lines = map("".join, self.canvas)
return os.linesep.join(lines)
def point(self, x: int, y: int, char: str) -> None:
"""Create a point on ASCII canvas.
View on GitHub (pinned to e32fa9a52e)
Solutions
- Clamp dimensions to a minimum: `max(cols, 2)` and `max(lines, 2)` before constructing.
- Use the default `DrawGraph(graph).draw()` path instead of constructing `AsciiCanvas` with computed sizes.
- If customizing `DrawGraph`, keep `node_size` and the derived canvas math well above 1.
Example fix
# before canvas = AsciiCanvas(int(width * ratio), int(height * ratio)) # can hit 1 # after canvas = AsciiCanvas(max(int(width * ratio), 2), max(int(height * ratio), 2))
Defensive patterns
Strategy: validation
Validate before calling
cols, lines = max(cols, 2), max(lines, 2) canvas = AsciiCanvas(cols, lines)
Prevention
- Clamp computed canvas dimensions to >= 2.
- Use the default DrawGraph(graph).draw() instead of manual sizing.
- Test auto-sizing code against the smallest possible graph.
When it happens
Trigger: Instantiating `AsciiCanvas(0, 10)`, `AsciiCanvas(80, 1)`, or with negative values; calling `AsciiCanvas`-based rendering with dimensions computed from graph size (e.g. `node_degree * scale`) where the computation yields 0/1 for tiny graphs.
Common situations: Auto-sizing logic that scales canvas size by the number of nodes/edges and collapses to <=1 for a minimal graph (single node, no edges); passing terminal width from a CI environment where `shutil.get_terminal_size()` reports tiny dimensions; customizing `DrawGraph` node size constants to 0.
Related errors
- char should be a single character
- x should be >= 0 and < number of columns
- Node with id {id} already exists
- Source node {source.id} not in graph
- Target node {target.id} not in graph
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/ddfd8469aafb454d.
Report an issue: GitHub.