refactor(core)!: panic-free builder validation — build() collects all configuration errors (034 Phase 2, #133)#138
Merged
Conversation
… configuration errors (#133) One failure model instead of two: builder methods never panic on user mistakes. TypedRecord setters, the connector-link finish() methods, and configure() record a ConfigError (skipping the conflicting registration) and build() returns a single DbError::InvalidConfiguration carrying every finding — record key and connector URL included — so one run surfaces every mistake. The spawn-time factory panics (missing buffer, record lookup) become build()-time checks; .buffer() after .link_to()/.link_from() is now legal. Duplicate keys and dependency-graph findings fold into the same collected report. Remaining panics on the builder path are internal invariants worded 'this is a bug in aimdb-core'. AnyRecord gains has_buffer() and drain_config_errors(). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Closes #133. Part of design 034 Phase 2 (review doc §3.4); second of three stacked PRs (#130 → #133 → #134). Builds on #137.
What
One failure model instead of two: builder methods never panic on user mistakes;
build()validates everything and returns all errors at once.ConfigError { record_key, url, message }+DbError::InvalidConfiguration { errors: Vec<ConfigError> }(code0x4003, included inis_configuration_error).TypedRecord::set_producer/set_transform/add_inbound_connector: mutual-exclusion violations and duplicate producer/transform are recorded and the conflicting registration is skipped (has_producer()staysfalseafter a conflicting.source()).OutboundConnectorBuilder::finish()/InboundConnectorBuilder::finish(): invalid URL, missing serializer/deserializer, unregistered scheme, transform/source conflicts → recorded with record key + URL; the link is not registered; the registrar is returned as usual so chains keep compiling.build()with key + link URL (previously: panic inside a factory closure during the connector phase, far from the user's mistake). Consequence:.buffer()after.link_to()/.link_from()is now legal — order-independent (covered by a new test).configure()re-registering a key with a different type: recorded, user closure skipped (wasassert!).DependencyGraphfindings (cycles, unregistered transform inputs) fold into the same collected report. Note for reviewers: callers matchingDuplicateRecordKey/CyclicDependencyfrombuild()must switch toInvalidConfiguration— flagged per the issue's directive to collect all errors.panic!/expects on the builder path are internal invariants only, worded "this is a bug in aimdb-core".AnyRecordgainshas_buffer()anddrain_config_errors()(breaking for external implementors).Acceptance criteria (from #133)
panic!/assert!intyped_api.rs/typed_record.rs/builder.rsshows only internal-invariant messagesbuild()call (build_reports_all_configuration_mistakes_at_once)make checkpasses; examples unchangedTests
The 6
#[should_panic]tests are converted to recorded-error assertions; new tests cover unregistered-scheme recording, the three-mistakes acceptance criterion, buffer-after-link order independence, linked-record-without-buffer at build(), andInvalidConfiguration's Display/error-code. The tokio adapter'stest_duplicate_key_errornow asserts the collected error instead of a configure-time panic.🤖 Generated with Claude Code