in rust/azure_iot_operations_protocol/src/common/aio_protocol_error.rs [92:168]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(message) = &self.message {
write!(f, "{message}")
} else {
match self.kind {
AIOProtocolErrorKind::HeaderMissing => write!(
f,
"The MQTT header '{}' is missing",
self.header_name.as_deref().unwrap_or("Not Specified")
),
AIOProtocolErrorKind::HeaderInvalid => write!(
f,
"The MQTT header '{}' has an invalid value: '{}'",
self.header_name.as_deref().unwrap_or("Not Specified"),
self.header_value.as_deref().unwrap_or("Not Specified")
),
AIOProtocolErrorKind::PayloadInvalid => write!(
f,
"Serialization or deserialization of the MQTT payload failed"
),
AIOProtocolErrorKind::Timeout => write!(
f,
"The timeout '{}' elapsed after {} ms",
self.timeout_name.as_deref().unwrap_or("Not Specified"),
self.timeout_value.map_or_else(
|| "Not Specified".to_string(),
|d| d.as_millis().to_string()
)
),
AIOProtocolErrorKind::Cancellation => write!(f, "The operation was cancelled"),
AIOProtocolErrorKind::ConfigurationInvalid => {
if let Some(property_value) = &self.property_value {
write!(
f,
"The property '{}' has an invalid value: {:?}",
self.property_name.as_deref().unwrap_or("Not Specified"),
property_value
)
} else {
write!(
f,
"The property '{}' has an invalid value: 'Not Specified'",
self.property_name.as_deref().unwrap_or("Not Specified")
)
}
}
AIOProtocolErrorKind::StateInvalid => write!(
f,
"Invalid state in property '{}'",
self.property_name.as_deref().unwrap_or("Not Specified")
),
AIOProtocolErrorKind::InternalLogicError => write!(
f,
"Internal logic error in property '{}'",
self.property_name.as_deref().unwrap_or("Not Specified")
),
AIOProtocolErrorKind::UnknownError => write!(f, "An unknown error occurred"),
AIOProtocolErrorKind::ExecutionException => write!(
f,
"The command processor encountered an error while executing the command"
),
AIOProtocolErrorKind::ClientError => {
write!(f, "An MQTT communication error occurred")
}
AIOProtocolErrorKind::UnsupportedVersion => {
write!(
f,
"Received data with an unsupported protocol version '{}', but only major protocol versions '{:?}' are supported.",
self.protocol_version.as_deref().unwrap_or("Not Specified"),
self.supported_protocol_major_versions
.as_deref()
.unwrap_or(&[])
)
}
}
}
}