toasty_core/error/
condition_failed.rs

1use super::Error;
2
3/// Error when a conditional operation's condition evaluates to false.
4///
5/// This occurs when:
6/// - An UPDATE with a WHERE clause matches no rows (condition didn't match)
7/// - A DynamoDB conditional write fails (ConditionalCheckFailedException)
8/// - An optimistic lock version check fails
9#[derive(Debug)]
10pub(super) struct ConditionFailed {
11    context: Option<Box<str>>,
12}
13
14impl std::error::Error for ConditionFailed {}
15
16impl core::fmt::Display for ConditionFailed {
17    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
18        f.write_str("condition failed")?;
19        if let Some(ref ctx) = self.context {
20            write!(f, ": {}", ctx)?;
21        }
22        Ok(())
23    }
24}
25
26impl Error {
27    /// Creates a condition failed error.
28    ///
29    /// This is used when a conditional operation's condition evaluates to false, such as:
30    /// - An UPDATE with a WHERE clause that matches no rows
31    /// - A DynamoDB conditional write that fails
32    /// - An optimistic lock version check that fails
33    ///
34    /// The context parameter provides information about what condition failed.
35    pub fn condition_failed(context: impl Into<String>) -> Error {
36        Error::from(super::ErrorKind::ConditionFailed(ConditionFailed {
37            context: Some(context.into().into()),
38        }))
39    }
40
41    /// Returns `true` if this error is a condition failed error.
42    pub fn is_condition_failed(&self) -> bool {
43        matches!(self.kind(), super::ErrorKind::ConditionFailed(_))
44    }
45}