Impl std::error::Error for a shape's ConstraintViolation struct (#3431)
## Motivation and Context
Each constrained shape has an associated `ConstraintViolation`
structure, which at the moment does not implement `std::error::Error`.
## Description
All of the `ConstraintViolation` structures now implements
`std::fmt::Display` and the `std::error::Error` marker trait. There is a
difference between the message used for `pub(crate) fn
as_validation_exception_field` and for `std::fmt::Display` as the latter
does not know of the particular field which is being set in the
structure. Hence, it uses the shape ID instead.
For example, for a constrained `int`, the following is the message used
in `Display`:
```
write!(f, "Value for `com.aws.example#MyNumberSensitive`failed to satisfy constraint: Member must be greater than or equal to 100")
```
and the following is used for `as_validation_exception_field`:
```
format!("Value at '{}' failed to satisfy constraint: Member must be greater than or equal to 100", &path),
```
## Testing
Tests have been added to ensure:
1. `std::fmt::Display` has all of the variants for the enum that
represents the associated `Error` type in the `ConstraintViolation`
struct.
2. `ConstraintViolation` implements `std::error::Error`.
---------
Co-authored-by:
Fahad Zubair <fahadzub@amazon.com>
Loading
Please register or sign in to comment