Skip to content

fix: keep FileNotFoundError catching a missing Graphviz dot - #680

Merged
fgmacedo merged 1 commit into
mainfrom
fgmacedo/fix-graphviz-not-found-compat
Oct 13, 2026
Merged

fgmacedo merged 1 commit into
mainfrom
fgmacedo/fix-graphviz-not-found-compat

Conversation

@fgmacedo

Copy link
Copy Markdown
Owner

Why

Before 3.2.2, a missing dot raised pydot 4.0.1's FileNotFoundError('[Errno 2] "dot" not found in path.') (checked with PATH=/nonexistent on pydot 4.0.1). #672 replaced it with GraphvizError(StateMachineError), so except FileNotFoundError around diagram generation would stop catching a missing Graphviz in a patch release.

What changes

Evidence

$ PATH=/nonexistent .venv/bin/python -c 'import pydot; g=pydot.Dot("g"); g.add_node(pydot.Node("a")); g.create_svg()'
FileNotFoundError: [Errno 2] "dot" not found in path.

$ timeout 120 uv run pytest tests/test_contrib_diagram_graphviz.py tests/test_contrib_diagram.py docs/diagram.md --cov=statemachine.contrib.diagram.graphviz --cov-branch --cov-report=term-missing
statemachine/contrib/diagram/graphviz.py      26      0      6      0   100%
173 passed

$ timeout 180 uv run pytest -n 4
2634 passed, 25 skipped, 44 xfailed

New tests run with dot removed from PATH (monkeypatch.setenv("PATH", tmp_path)) through run_graphviz and format(sm, "svg"). They assert pytest.raises(FileNotFoundError), isinstance of GraphvizNotFoundError and GraphvizError, errno, and the exact message.

Not verified

  • Windows: not run. CPython raises FileNotFoundError for a missing executable there as well, so it should take the same branch.
  • strerror and args differ from pydot's old exception (strerror is None and args == (message,), where pydot gave (2, message)). Only the except FileNotFoundError and errno contracts are kept.

Refs #672
Refs #649

GraphvizError replaced pydot's FileNotFoundError for a missing dot in
3.2.2, which breaks code that skips diagrams with except FileNotFoundError.
A missing program now raises GraphvizNotFoundError, a subclass of both
GraphvizError and FileNotFoundError with errno ENOENT.

Refs #672, #649

Signed-off-by: Fernando Macedo <fgmacedo@gmail.com>
@fgmacedo fgmacedo added this to the 3.2.2 milestone Oct 13, 2026
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (73bf57c) to head (e62fc80).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #680   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           53        53           
  Lines         5787      5793    +6     
  Branches       918       918           
=========================================
+ Hits          5787      5793    +6     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fgmacedo
fgmacedo merged commit c9e991b into main Oct 13, 2026
14 checks passed
@fgmacedo
fgmacedo deleted the fgmacedo/fix-graphviz-not-found-compat branch October 13, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant