Repository navigation
refactor: simplify the creation API and parser errors (#380 part 3b) - #391
Merged
Merged
Conversation
Replace the seven create_database* functions with create_database(path, &DatabaseSpec, budget). DatabaseSpec holds the tables with their initial rows, the relationships, and a RelationshipLayout choosing between the relationship-graph layout (default) and the EXP-0118/0122 single Long relationship layout, whose bytes differ from the graph layout for the same request. Candidate image checks move to create/check.rs.
UpdateError and CreateDatabaseError become one public WriteError in write/error.rs, returned by insert, update, delete, schema edits and create_database. Creation failures keep their messages through the Compose and CreatePublish variants. The candidate image check error is crate-private, and the lossy From<UpdateError> for ColumnPropertyError is replaced by an explicit crate-private mapping at its one call site.
Replace hand-written Display, Error, source and From impls with
thiserror derives. Messages are unchanged; Debug-based messages use an
enum-level #[error("...{self:?}")]. ValidationError and PublishError
keep hand-written Display because their text branches on runtime data;
a few From impls that map between variants stay manual.
minimum_row fell back to a full null set when a layout had more than
255 columns. Return Unsupported("row column count") instead.
This was referenced Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 3b of #380. This simplifies the parser's public creation API and merges its write errors, then derives the parser error impls with thiserror. Databases produced by the library are byte-identical, and every error message is unchanged.
Creation API
Before: seven public functions:
create_databasecreate_database_with_rowscreate_database_with_table_rowscreate_database_with_relationshipcreate_database_with_relationship_rowscreate_database_with_relationshipscreate_database_with_relationships_and_rowsAfter: one function,
create_database(path, &DatabaseSpec, budget) -> Result<(), WriteError>.Migration:
Inside
create_database, requests still go to the same composer and checks as before:Graphrelationships use the graph path.SingleLonguses the single-relationship path, with or without rows.TableRows::emptyis a new convenience constructor. The CLI now picks the layout from itsrelationshipsorrelationshipJSON field and makes a single call.Two edge cases now behave differently:
SingleLongrequest with no rows used to refuse a parent table with a second index. It now succeeds.Two tests that relied on the old refusals were changed to supply one row so they still exercise the rows-path refusal.
Single-relationship path: kept, because its bytes differ
Before deleting anything, I checked whether the graph path could replace the single-relationship path. A temporary probe (not committed) composed every single-relationship request twice, once through the single path and once through the graph path, and compared the bytes. It covered every such request in the golden corpus and the
create::tests. None of the successful cases matched.0x02). The graph path writes the creation counter there (0x04for two tables). This affects every case.0; the graph path writes the key or row count (0x14, 0xc8, 0xc9, 0x04 and 0x01 were seen).Following the brief, I did not delete the path. It is now internal (
pub(super)) and reached throughRelationshipLayout::SingleLong, whose doc comment explains how its bytes differ. Its tests are unchanged.Errors
Before: 42 public
*Errortypes (49 including crate-private ones), about 135 hand-written Display/Error/From impls andconversion!lines.UpdateError(26 variants) andCreateDatabaseError(2 variants) were separate public types.ImageCheckErrorwas declaredpubinside a private module.From<UpdateError> for ColumnPropertyError.After: 40 public (48 in total), with 8 hand-written impls left.
WriteError(write/error.rs) is the single error for insert, update, delete, schema edits andcreate_database.UpdateErrorvariants keep their names, so theirfield update failed: {self:?}text is identical.Compose(ComposeError), which prints "database composition failed: …", andCreatePublish(PublishError), which prints "database publication failed: …".ImageCheckErroris nowpub(crate)increate/check.rs. The creation-time candidate checks have moved there as well.Fromis replaced by a crate-privateColumnPropertyError::from_ownership_check, used at its one call site.ColumnPropertyErrorstays as the property reader's error.ReadErrorumbrella.ComposeError::Propertiesnow boxes its payload, which keepsWriteErrorunder clippy'sresult_large_errlimit. Box's Debug output is transparent, so the message text is unchanged.thiserror 2.0.21 derives Display, Error,
sourceandFromfor the remaining parser errors. Debug-based messages use an enum-level#[error("…{self:?}")]. Some impls stay hand-written:ValidationErrorandPublishErrorkeep a hand-written Display, because their text depends on runtime data.Fromimpls stay manual: some map one source error onto several variants, and in others#[from]would have changed whatsource()returns.cargo deny checkpasses: advisories, bans, licenses and sources are all ok. CLI and testkit errors were not converted.Also
row/insert_page.rs:minimum_rownow returnsUnsupported("row column count")when a layout has more than 255 columns. It used to fall back silently to a full set of nulls. A focused test covers this.Checks
scripts/golden-check.sh 9ee8a73reports 1923 files, all identical, after every commit.cargo test -p jet3gives 825 passed + 6 ignored in the lib (was 823 + 6), 17 integration and 2 doc tests (unchanged). The two new tests are theWriteErrormessage prefixes andminimum_row. No tests were removed or merged.cargo check -p jet3 --all-targets --target x86_64-pc-windows-gnuis clean.just readypasses.Line counts
Production code in
crates/jet3/src(excluding*_tests.rs,tests.rsandtestkit.rs) went from 41,849 lines to 40,692.Not touched:
oracle/windows-dao/protocol/v1_2/README.mdstill names the oldcreate_database_with_*functions. It is outside this PR's scope because an oracle PR is in flight.🤖 Generated with Claude Code