Skip to content
Unverified Commit 42701d5b authored by Fahad Zubair's avatar Fahad Zubair Committed by GitHub
Browse files

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: default avatarFahad Zubair <fahadzub@amazon.com>
parent 1f5cb697
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment