2.1 KiB
2.1 KiB
Prompt
Follow-up to a /code-review of PR #460 (this branch) which surfaced lower-severity findings in the .. d2:: sphinx directive. The user’s driving instructions across the session,
yup do both at least, then report back.
(re: “implement #7 (+ optionally #8) on the branch”) and,
well we’re on a clean main so why not just do these now too?
(re: also doing #9). The three findings being addressed,
- #7: a
d2render that is attempted and fails (binary present but errors on the source) silently degraded to the stale committed SVG and the build still exited 0, - #8:
parallel_*_safe = Truewas declared whilerun()writes the shared output SVG during the read phase (torn write undersphinx-build -j), - #9: output keyed only by
src.stemso two.d2sources with the same stem collide.
Response summary
Reworked docs/_ext/d2diagrams.py,
render_svg()now returns aRenderResulttristate (OK/FELL_BACK/NO_OUTPUT/FAILED) sorun()can distinguish a graceful no-binary fallback from a real render failure;FAILEDemits areporter.error(build fails under-W),- the render writes into a sibling temp-file then
os.replace()(atomic) so a failed/torn render can never clobber a good committed SVG, - a per-build
_seen_outputsmap (reset onbuilder-inited) errors on a same-stem output collision.
Verified: a corrupted .d2 errors under -W (exit 1) with the committed SVG byte-unchanged; the collision guard fires on a duplicate stem; nix run nixpkgs#d2 render path + atomic swap leave no temp residue; ruff clean.
Response summary (cont.) — Files changed
docs/_ext/d2diagrams.py— tristate render result, atomic temp-file render, output-collision guard, doc-string policy update.
Human edits
None — committed as generated (3a5cfde0). The user noted follow-up refinements may come in later commits.