#1263·diagrams

Node.connect constructs validation errors without raising them

Author: xu91102Created Sep 26, 2026Updated Sep 26, 2026

Problem

Node.connect() checks that its two arguments are a Node and an Edge, but constructs ValueError objects without raising them. Invalid arguments therefore continue into the Graphviz call and fail with an unrelated AttributeError instead of the intended validation message.

Reproduction

On master 0cd0d84016087eead0f7a5b747571b3f92b56726:

python
from diagrams import Diagram, Edge, Node

with Diagram('invalid connection', show=False):
    source = Node('source')
    source.connect('not a node', Edge())
# AttributeError: 'str' object has no attribute 'nodeid'

Passing a valid target node but a string as the edge similarly fails with 'str' object has no attribute 'attrs'.

Expected behavior

Raise the ValueError already present in each validation branch, with the existing not a valid Node / not a valid Edge message, before attempting to add an edge. Valid connections should retain their behavior.

Reproduced on Python 3.12/macOS with Graphviz 16.1.0; two regression tests exercise these public Node.connect() calls.