Skip to content

Conversation

@doriable
Copy link
Member

Instead of setting CompilationErrors found in the build process on the
mesasge evaluator, this sets them on their respective field evaluators.
They are then returned when the field is evaluated. This ensures that
all constraints ae built, even when a CompilationError is encountered.

This makes the Filter API easier to use because then all constraints
are built, and then CompilationErrors are returned during the
evaluation layer.

The main change is that CompilationErrors are no longer "fail fast"
immediately, and instead allow for all constraints to be built and
cached.

Fixes #204

This adds some tests around the expected behaviours of
`CompilationError` and `Filter`:

`CompilationErrorNoViolations` tests that we expect to get a
`CompilationError` back from invalid constraints defined in the source
file, in this case, a mismatch in field type and constraint type. This
is currently behaving as expected and the test passes.

`CompilationErrorWithViolations` tests that in the case where a
`CompilationError` exists and a different field also violates the
constraint, we are only returning the `CompilationError` that was found.
This is behaving as expected and the test passes.

`FilterIncludeCompilationError` tests that if there is a `CompilationError`
on a field and we set a filter for the field with the
`CompilationError`, we should get a `CompilationError` in return. This
is currently not the behaviour, since we return early in the case of a
`CompilationError`, and then we go to evaluate the message. Since the
`CompilationError` is set on the message evaluator, and the message
descriptor is not the field descriptor we are filtering for, the
`CompilationError` is lost.

`FilterExcludeCompilationError` tests that if a filter excludes a
field with a `CompilationError`, we should still return the other
violations. This is currently not behaving as expected depending on the
field ordering due to the early return behaviour -- we may not have compiled
the constraint for the field, and so it is not evaluated.
Instead of setting `CompilationError`s found in the build process on the
mesasge evaluator, this sets them on their respective field evaluators.
They are then returned when the field is evaluated. This ensures that
all constraints ae built, even when a `CompilationError` is encountered.

This makes the `Filter` API easier to use because then all constraints
are built, and then `CompilationError`s are returned during the
evaluation layer.

The main change is that `CompilationError`s are no longer "fail fast"
immediately, and instead allow for all constraintas to be built and
cached.
@doriable doriable requested review from a user, rodaine and timostamm March 13, 2025 22:11
@github-actions
Copy link

github-actions bot commented Mar 13, 2025

The latest Buf updates on your PR. Results from workflow Buf / validate-protos (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMar 13, 2025, 10:13 PM

@doriable doriable marked this pull request as draft March 14, 2025 00:25
@doriable doriable marked this pull request as ready for review March 17, 2025 15:31
@doriable
Copy link
Member Author

This has been validated with the upgrade to bufbuild/buf, bufbuild/buf#3652

@doriable doriable merged commit 38a1748 into main Mar 17, 2025
9 checks passed
@doriable doriable deleted the handle-compilation-error branch March 17, 2025 16:06
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.

Allow evaluating constraints with Filter set even when a CompilationError is found

2 participants