Repository navigation
Add the shared building blocks of the domain model - #4888
Conversation
Result, ViolationDiagnostics, ConfigurationException, LoaderPipeline, DomainOperation and the equality comparers are the foundation the per-aggregate changes of #4530 build on. Nothing here changes what a loader accepts, reports or writes: the only edit to existing code is an unused RuleId property on Diagnostic. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
| catch (Exception e) when (e is not OutOfMemoryException) | ||
| { | ||
| return Failed<T>(file, e.Message); | ||
| } |
There was a problem hiding this comment.
Severity: P3 (Low)
Build turns any thrown exception into a diagnostic that holds only e.Message. It drops the inner exception and the stack trace. YamlDotNet wraps converter and constructor failures as YamlException("...: Exception during deserialization") and puts the real cause in InnerException, so loaders moved onto this pipeline will report a generic message. Existing EmitError(file, message, e) includes the exception and its inner exception. Bugs in map, such as a NullReferenceException, also lose the stack needed to find them.
Generated by Libra. Specialist: libra-complexity. React with 👍 or 👎 to give feedback on this comment.
There was a problem hiding this comment.
I kept the default message on purpose: area pull requests must reproduce today's diagnostics byte for byte, and that text differs per loader. A new LoadOptions.Describe lets a loader opt in to richer text (message, exception, inner). OperationCanceledException now propagates alongside OutOfMemoryException. Both are tested.
There was a problem hiding this comment.
The default message is still the exception's message. Loader.For(..., describe:) is declared with the loader, so an area can opt in to richer text. OperationCanceledException and OutOfMemoryException propagate; both are tested.
Docs preview (local build)Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4888/ Sample changed pages: |
…line LoaderPipeline now looks the rules up through IHaveConstraints and takes a LoadOptions record instead of seven optional parameters. It also keeps findings made before a failed map, lets a loader shape the error text, and lets cancellation propagate. Review follow-ups: BufferingDiagnosticsCollector uses the base lifecycle, DomainOperation takes a required file, and the unused ParseLifecycle and Props generators are gone. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…en rules Rules resolve from the type (T.Constraints) and nothing in src outside the domain can author or run one: BannedSymbols.txt makes that a compile error. LoaderPipeline, LoadOptions and DomainOperation give way to Loader<TDto,T> with a MapContext, LoadResult<T> (a union of Loaded and Unreadable, no longer clashing with Nullean.Entities.Result), operations as methods on the record verified by AutoTest, and stages as types in a union. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Props.cs fixed one seed for all property tests. A fixed seed hides what another seed would find, so the tests now use CsCheck's random default, print the seed on failure and replay it from CsCheck_Seed. AutoTest defaults to a fixed seed, so Widget passes RunSeed explicitly. The conventions require a pinned example test for each bug a property test finds. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Adds the shared types the per-aggregate pull requests of #4530 build on: a loader declaration, a load result, the violation-to-diagnostic mapping, the equality comparers and a compile-time ban on writing rules outside the domain. Nothing here changes what a loader accepts, reports or writes.
Affects: Internals only
Stack: 1 of N, the foundation of #4530, which this series splits. Later pull requests add one aggregate each on top of this one.
Prompt summary: Split the large domain-model pull request (#4530) into reviewable pieces. This first piece takes only the shared building blocks, as a pure addition on top of
main, so each later piece depends on it and nothing else. Review of the first version changed the design: rules are static per type, loaders are declared once, and the load result is a union.Why
#4530 changes about 700 files. The types every aggregate needs are easy to review on their own, and the later pull requests cannot start without them. The shape they set is copied by every area, so it has to be right before any area depends on it.
What
Rules resolve from the type, and the ban
A record implements
IHaveConstraints<T>with one staticConstraintsdeclared in a*Constraintsclass. There is no override and no composing of sets in loader code.BannedSymbols.txt(Microsoft.CodeAnalysis.BannedApiAnalyzers 3.3.4, analyzer only, RS0030) makesConstraints<T>,Relation,Tree, the staticConstraintSetand running a set by hand (Report,Validate,Validated,Ensure,Check) a compile error in everysrcproject exceptElastic.Documentation. Tests are exempt, andLoader.cssuppresses the rule once because it is the one place that runs a set.Loaders declared once
Loader<TDto,T>, created withLoader.For(parse: (text, file) => ..., map: (dto, context) => ...), has one entry,Load(text, file). The map step reports to aMapContextthat the loader owns, so findings are kept, in order, even when a later step throws.errorsAreFatalanddescribe(the error text for a step that threw; the default is the message, so area pull requests keep today's diagnostics) belong to the declaration. Cancellation and out-of-memory propagate.value.Check(file)checks a record built elsewhere.UnknownYamlKeysandBufferingDiagnosticsCollector(base lifecycle) stay.LoadResult
LoadResult<T>is a union ofLoaded<T>(value and findings, a tolerant load may still hold errors) andUnreadable<T>(findings only), replacingResult<T>, which clashed withNullean.Entities.Result<T>.Report,EmitTo,EmitErrorsTo,OrThrowandOrThrowIfMissingkeep their behaviour.ConfigurationExceptionstops the process with every error.Operations and stages
Operations are public methods on the record returning the record, checked by
T.Constraints.Apply, and verified byAutoTest(Nullean.Entities.CsCheck) inWidgetAutoTests.ApplyOutcome.ToDiagnostics(file)maps the outcome to findings, including the warningsApplydrops. A rule that holds at one stage is a stage type with its ownConstraints, joined in aunionso a switch must cover every stage (WidgetStage).DomainOperationis removed.Equality, packages and docs
FileSystemInfoLocationComparerandStringListEntryComparergiveGenerator.Equalsa way to compare files and string-list dictionaries.Nullean.Entities0.2.0 is referenced byElastic.Documentation; the test project addsNullean.Entities.CsCheck.Constraints-Conventions.mdsays where rules live, how loaders, operations and stages are written, and what the ban prevents.Diagnosticgains an unreadRuleId.Deviations from the plan.
[Constraints<T>]on a static class does not make the record implementIHaveConstraints<T>, so each record declares the one-lineConstraintsproperty by hand.ApplyandApplyDetailedare not banned, because they are the checked form of an operation. CS8509 (a missing union case) is a warning in test projects and an error insrc. The oldFileOfoption has no replacement yet.Not in this PR. The
DiagnosticsCollectorde-duplication byRuleId, every*Constraintsclass of an area, the area loaders, DTO renames, the link-registry and floating-alias comparers,DomainOperation.ParseLifecycle, the guard, ledger and golden tests, and any change in consuming code.Needed by later PRs.
SourcePosition(documentation sets),UnknownYamlKeys,Loader,MapContext,LoadResultandConfigurationException(every loader),StringListEntryComparer(changelog and products configuration),FileSystemInfoLocationComparer(documentation sets),ApplyOutcome.ToDiagnostics(operations in links and release notes). The rest is exercised by the tests added here.Verify
mise run build mise run test mise run lintEvery new piece has a test, and I broke each on purpose (finding order, cancellation, fatality, describe, the
EmitErrorsToandOrThrowcontracts, the outcome adapter, a stage case, an operation that breaks a rule) and saw it fail. A deliberateConstraints<T>,ConstraintSet.FromandValidateinElastic.Documentation.Configurationfails the build with RS0030. The earlier golden build of the isolated, assembler and codex sites against the base commit differed in 0 of 23103 isolated files and 0 of 57053 assembler files. In the codex site 4 of 23248 files differ, the same 4 that differ between two runs of the base commit itself. No build path changed since.