eloquent_core/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#[derive(Debug, PartialEq)]
pub enum EloquentError {
    MissingTable,
    DuplicatedColumnNames(String),
    DuplicatedConditions(String),
    HavingClauseWithoutAggregateFunction(String),
    GroupByWithNonSelectedOrAggregateFunction(String),
    OrderByWithNonSelectedOrAggregateFunction(String),
    MultipleCrudActions,
    MissingPlaceholders,
    CannotApplyClauseOnInsert(String),
    CannotApplyClauseOnUpdate(String),
    CannotApplyClauseOnDelete(String),
    CannotUseOffsetLimitWithPagination(String),
    InconsistentInsertColumns,
}

impl std::error::Error for EloquentError {}

impl std::fmt::Display for EloquentError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            EloquentError::MissingTable => write!(f, "Missing table"),
            EloquentError::DuplicatedColumnNames(column) => {
                write!(f, "Duplicated column name '{}'", column)
            }
            EloquentError::DuplicatedConditions(column) => {
                write!(f, "Duplicated conditions '{}'", column)
            }
            EloquentError::HavingClauseWithoutAggregateFunction(column) => {
                write!(f, "HAVING clause without aggregate function '{}'", column)
            }
            EloquentError::GroupByWithNonSelectedOrAggregateFunction(column) => {
                write!(
                    f,
                    "GROUP BY without selected column or aggregate function '{}'",
                    column
                )
            }
            EloquentError::OrderByWithNonSelectedOrAggregateFunction(column) => {
                write!(
                    f,
                    "ORDER BY without selected or aggregate function '{}'",
                    column
                )
            }
            EloquentError::MultipleCrudActions => write!(f, "Multiple CRUD actions"),
            EloquentError::MissingPlaceholders => write!(f, "Missing placeholders"),
            EloquentError::CannotApplyClauseOnInsert(clause) => {
                write!(f, "Cannot apply clause '{}' on INSERT", clause)
            }
            EloquentError::CannotApplyClauseOnUpdate(clause) => {
                write!(f, "Cannot apply clause '{}' on UPDATE", clause)
            }
            EloquentError::CannotApplyClauseOnDelete(clause) => {
                write!(f, "Cannot apply clause '{}' on DELETE", clause)
            }
            EloquentError::CannotUseOffsetLimitWithPagination(clause) => {
                write!(f, "Cannot use '{}' with PAGINATION", clause)
            }
            EloquentError::InconsistentInsertColumns => write!(
                f,
                "INSERT statement has inconsistent column counts across rows"
            ),
        }
    }
}