Skip to content

Assert what a failure carries rather than inspect it - #11

Merged
tamnd merged 1 commit into
mainfrom
conditions
Aug 22, 2026
Merged

Assert what a failure carries rather than inspect it#11
tamnd merged 1 commit into
mainfrom
conditions

Conversation

@tamnd

@tamnd tamnd commented Aug 22, 2026

Copy link
Copy Markdown
Owner

The conditions item of the practice scorecard, which reads: every failure carries the standard's condition code, the place, and the doc URL, checked by a test rather than promised in a page.

Two of the three were not checked here, and the third was checked in a way that could not fail.

The assertion that passes when the field is missing

e.position()
    .ifPresent(
        p -> {
          assertTrue(p.line() >= 1, "line " + p.line());
          ...
        });

That is green when there is no position. So was the caret assertion beside it. The one outcome worth failing for is the one it lets through, and a suite with a few of these in it stops being evidence.

Where a field is genuinely optional the case that has it and the case that does not are now two tests, and each one says which it is. A syntax error has a position and the test asserts it. A connection used after close has none, and the test asserts that too, because a misuse that borrowed a condition code would send a reader to a page about something else.

The doc URL

Never checked anywhere. It is now asserted to be the base plus the code exactly as the code is written:

assertEquals(DOCS + e.code().orElseThrow(), e.docUrl().orElseThrow());

Exactly, because a condition class can have a letter in it, 01G11 for one, and a URL that lower cased the code would be a 404 that nobody notices until somebody clicks it.

What else went in

  • the offset is where the token starts, so a caller who still has the text can slice at it, checked by slicing
  • the caret sits under the column, checked by the index of the ^
  • a name nothing bound is 42002 and not merely something in class 42
  • a connection used after close carries MISUSE_CLOSED, no code and no page, deliberately
  • a database that is not there names the path it looked for, since that is the one thing the class does not tell you
  • the condition classes are subclasses of the one, and the one is unchecked
  • a diagnostic for a call that never reached the engine leaves every field empty rather than filling it with a zero that reads like a place in the text

Checked

On a server, against libzu built from the engine at HEAD.

  • mvn test -pl zudb-ffm -am -Dtest=ErrorTest: 13 of 13
  • mvn test -pl zudb-jni -am -Dtest=ErrorTest: 13 of 13, same cases through the other provider
  • mvn test over the whole reactor: build success, every module green, both providers

This takes zu-java from 25 to 35 of 90 on practice. The two items it already held and nobody had recorded are reference, since the javadoc is generated and published with the release, and idiom, since the API is records, a sealed Value, AutoCloseable on every handle, Stream<Row> and unchecked exceptions. The scorecard said zero for all ten, which was never an audit, only a row nobody had filled in.

The error model promises three things on every condition: the
GQLSTATUS code, the place in the statement, and the page that
documents it. Two of the three were untested here, and the third was
tested in a way that could not fail.

The position test read `e.position().ifPresent(p -> assertTrue(...))`,
which passes when there is no position at all. So did the caret. That
is the shape of assertion that turns a suite into a page of promises
with a green tick on it: the one outcome worth failing for is the one
it lets through. Where a field is genuinely optional now, the case
that has it and the case that does not are two tests and each says
which it is.

The doc URL was never checked anywhere. It is the field a program
hands a reader instead of five characters to go and search for, and
it is now asserted to be the base plus the code exactly as the code
is written. Exactly, because a condition class can have a letter in
it and a URL that lower cased it would be a 404 nobody would notice
until somebody clicked it.

Added with it: that the offset is where the token starts and a caller
who still has the text can slice at it, that the caret sits under the
column, that a name nothing bound is 42002 and not merely something
in class 42, that a connection used after close carries the misuse
status and deliberately carries no code and no page because it never
reached the engine, that a database that is not there names the path
it looked for, that the condition classes are subclasses of the one,
and that a diagnostic for a call that never happened leaves every
field empty rather than filling it with a zero that reads like a
place in the text.

Thirteen cases, run twice, once on each provider. Green on both
against libzu at the engine's HEAD.
@tamnd
tamnd merged commit 9091d3b into main Aug 22, 2026
9 of 17 checks passed
@tamnd
tamnd deleted the conditions branch August 22, 2026 08:21
tamnd added a commit to tamnd/zu that referenced this pull request Aug 22, 2026
The row said zero on all ten items, which was not an audit. It was a
row nobody had filled in, and a scorecard with a placeholder in it is
worse than one with a gap, because the placeholder reads like a
measurement.

Audited, zu-java held two of them already. reference, because the
javadoc is generated and published with the release rather than
written by hand beside it, and CI builds it on every push so it
cannot rot quietly. idiom, because the API is records, a sealed
Value, AutoCloseable on every handle, Stream<Row> for iteration, text
blocks in the examples and unchecked exceptions with a retryable
field rather than a checked one on every signature.

conditions is the third and it landed today, tamnd/zu-java#11. The
code, the place and the doc URL are asserted on every failure that
has them and asserted absent on the failures that do not, which is
the part the old test could not do.

35 of 90. quickstart, misuse, leaks, install and stability are the
apparatus still to build, and api-map and perf are reports.
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