Description
When a shape is annotated with @error
, the code generator implements the std::error::Error
and std::fmt::Display
trait for that error structure. However, if this error structure contains a member field that references another structure, the code generator doesn't implement Display
for the referenced structure, resulting in compilation errors.
For example, the following model generates uncompilable code:
@error("client")
structure ErrorInInput {
message: ErrorMessage
}
structure ErrorMessage {
@required
statusCode: String
@required
errorMessage: String
requestId: String
}
The root cause is that when a shape is annotated with @error
, the code generator implements std::error::Error
for that type:
impl std::error::Error for ErrorInInput {}
This implementation requires that the type also implements the Display
trait. While the code generator correctly implements Display
for ErrorInInput
, it attempts to forward the display implementation to the message
field. However, since ErrorMessage
structure doesn't have a Display
implementation, compilation fails.
Generated Code
pub struct ErrorInInput {
#[allow(missing_docs)] // documentation missing in model
pub message: ::std::option::Option<crate::model::ErrorMessage>,
}
impl ::std::fmt::Display for ErrorInInput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
::std::write!(f, "ErrorInInput")?;
if let ::std::option::Option::Some(inner_2) = &self.message {
{
::std::write!(f, ": {}", inner_2)?;
}
}
Ok(())
}
}
impl ::std::error::Error for ErrorInInput {}