Skip to content

An input with no graph in it is nothing to draw: exit 0, as Graphviz's dot; it was 1 - #156

Merged
closer-claudio merged 1 commit into
mainfrom
claudio/20261122-empty-input
Nov 23, 2026
Merged

closer-claudio merged 1 commit into
mainfrom
claudio/20261122-empty-input

Conversation

@closer-claudio

Copy link
Copy Markdown
Contributor

dot exited 1 on an input with no graph in it: empty, blank, or comments alone. Graphviz's dot renders nothing for such an input and exits 0. This command now does the same.

This breaks a caller that relied on the failure: a pipeline that fed dot nothing got status 1 and now gets status 0 and no output.

What Graphviz does

Measured with Graphviz's dot 16.1.1 on an empty input, a blank one, a line comment, a block comment and a preprocessor line:

  • exit status 0, nothing on standard output, nothing on standard error;
  • with -o to a new path, no file is made;
  • with -o over an existing file, the file is left as it was.

A text it cannot read (digraph { a -> , a bare word) is exit 1.

The change

  • run (cmd/dot/main.go) reads and parses the input before it decides where to write. A text that holds no graph ends there with status 0: nothing is written, and under -o no temporary file is made, so nothing is renamed over the output.
  • "No graph" is go-graphviz's cgraph.ErrNoGraph (ParseBytes says when a text holds no graph: cgraph.ErrNoGraph, apart from a syntax error go-graphviz#248), which is held to Graphviz's dot there. The module is required at the commit on its main that carries it, 1880f86 (v0.6.1-0.20261122214648-1880f8661dd1), which also brings its fixes since v0.6.0: a JPEG is white where the page is transparent, a string of quotes is written whole, a dashed edge far from the page is drawn in the page's memory.
  • The check for a nil graph after a parse without error is removed: go-graphviz never returns one.
  • The README says it, beside the exit statuses.

Evidence

  • TestATextWithNoGraphIsNothingToDraw (cmd/dot/contract_test.go) runs the built command on the five texts above, in three formats, to standard output, to a new path and over an existing file: status 0, both streams empty, the directory as it was. Where the test has a Graphviz dot (DOT_ORACLE), it holds the same texts to it. Two texts that cannot be read stay exit 1 with a parse error. It replaces TestEmptyInputIsAnError and the "empty input" row of the contract table, which held the old status.
  • FuzzInput holds the line from the other side: an exit 0 with nothing on standard output is a text go-graphviz says holds no graph, and only that. Its corpus passes, and 30 seconds of fuzzing on four workers found nothing.
  • just lint and just test pass; the oracle test (TestDOTIsGraphvizsDOTBothWays) passes against Graphviz's dot 16.1.1.

…s dot; it was 1

For an input that is empty, blank or comments alone, Graphviz's dot
renders nothing and exits 0: nothing on either stream, and with -o no
file made and the one at the path left as it was (measured with dot
16.1.1). This command exited 1 with "parse input: graphviz: no graph was
produced", and its tests held it to that.

run now reads and parses the input before it picks where to write, and
a text go-graphviz says holds no graph (cgraph.ErrNoGraph) ends there
with status 0. A text that cannot be read is a failure as before. The
check for a nil graph after a parse without error is gone: go-graphviz
returns none.

go-graphviz is required at the commit on its main that has the error,
1880f86, which also carries its fixes since v0.6.0.

The contract test holds each case to the status, the two streams and
the directory, and to Graphviz's dot where the test has one; the fuzz
target holds that an exit 0 with nothing written is a text with no
graph in it, and only that.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: closer-claudio <claudio@farcloser.world>
@closer-claudio closer-claudio added the breaking Breaks a consumer label Nov 22, 2026
@closer-claudio

Copy link
Copy Markdown
Contributor Author

Reviewed at 1083363

@closer-claudio
closer-claudio merged commit cc283c7 into main Nov 23, 2026
14 checks passed
@closer-claudio
closer-claudio deleted the claudio/20261122-empty-input branch November 23, 2026 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaks a consumer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants