You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an operation's input includes an event streaming member, the builder for the operation input or output can raise a ConstraintViolation if build_enforcing_all_constraints is called and the event streaming member field has not been set.
The From implementation that converts ConstraintViolation to RequestRejection references ValidationException. However, if the user has not added ValidationException to the errors list, a build-time error is not generated to prompt the user to include ValidationException.
The From implementation for converting ConstraintViolation to RequestRejection uses crate::error::ValidationException:
impl ::std::convert::From<ConstraintViolation>
for ::aws_smithy_http_server::protocol::rpc_v2_cbor::rejection::RequestRejection
{
fn from(constraint_violation: ConstraintViolation) -> Self {
let first_validation_exception_field =
constraint_violation.as_validation_exception_field("".to_owned());
let validation_exception = crate::error::ValidationException {
The generated Rust code errors out with:
error[E0412]: cannot find type `ValidationExceptionField` in module `crate::model`
--> src/input.rs:78:28
|
78 | ) -> crate::model::ValidationExceptionField {
| ^^^^^^^^^^^^^^^^^^^^^^^^ not found in `crate::model`
The text was updated successfully, but these errors were encountered:
You must always have ValidationException in an event streaming operation because the event (the member on the input structure that targets a Smithy union/ Rust enum) is always required.
drganjoo
changed the title
operationsThatMustHaveValidationException does not account for event streaming members.operationShapesThatMustHaveValidationException does not account for event streaming members.
Sep 3, 2024
…eption` (#3814)
This PR addresses an issue where, if an operation's input includes an
event streaming member, the builder for the operation input or output
may raise a `ConstraintViolation` when `build_enforcing_all_constraints`
is called and the event streaming member field is not set. This occurs
because the member shape is required.
The standard error message that is shown when `ValidationException` is
not attached to an operation is also displayed in this case:
*Operation test#TestOperation takes in input that is constrained
(https://awslabs.github.io/smithy/2.0/spec/constraint-traits.html), and
as such can fail with a validation exception. You must model this
behavior in the operation shape in your model file.*
```smithy
use smithy.framework#ValidationException
operation TestOperation {
...
errors: [..., ValidationException] // <-- Add this.
}
```
Closes: [3813](#3813)
---------
Co-authored-by: Fahad Zubair <[email protected]>
When an operation's input includes an event streaming member, the builder for the operation input or output can raise a
ConstraintViolation
ifbuild_enforcing_all_constraints
is called and the event streaming member field has not been set.The
From
implementation that convertsConstraintViolation
toRequestRejection
referencesValidationException
. However, if the user has not addedValidationException
to the errors list, a build-time error is not generated to prompt the user to includeValidationException
.The operationShapesThatMustHaveValidationException method should raise an error in this case.
Here is a sample model:
In the operation input builder,
build_enforcing_all_constraints
returns aConstraintViolation
if constraints are not met:The
From
implementation for convertingConstraintViolation
toRequestRejection
usescrate::error::ValidationException
:The generated Rust code errors out with:
The text was updated successfully, but these errors were encountered: