• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

joaoh82 / rust_sqlite / 25965562167

16 May 2026 03:21PM UTC coverage: 68.778% (-0.08%) from 68.857%
25965562167

Pull #140

github

web-flow
Merge d3d5d199a into a38023afc
Pull Request #140: feat(examples): SQLR-39 Python LLM agent with persistent memory

11151 of 16213 relevant lines covered (68.78%)

1.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

9.35
/src/error.rs
1
use thiserror::Error;
2

3
use std::result;
4

5
use sqlparser::parser::ParserError;
6

7
/// This is a type that encapsulated the `std::result` with the enum `SQLRiteError`
8
/// and makes function signatures easier to read.
9
pub type Result<T> = result::Result<T, SQLRiteError>;
×
10

11
/// SQLRiteError is an enum with all the standardized errors available for returning
12
///
13
#[derive(Error, Debug)]
14
pub enum SQLRiteError {
15
    #[error("Not Implemented error: {0}")]
16
    NotImplemented(String),
17
    #[error("General error: {0}")]
18
    General(String),
19
    #[error("Internal error: {0}")]
20
    Internal(String),
21
    #[error("Unknown command error: {0}")]
22
    UnknownCommand(String),
23
    #[error("SQL error: {0:?}")]
24
    SqlError(#[from] ParserError),
25
    #[error("IO error: {0}")]
26
    Io(#[from] std::io::Error),
27
    /// Phase 11.4 — `BEGIN CONCURRENT` commit hit a write-write
28
    /// conflict. Some other transaction committed a newer version
29
    /// of a row in this transaction's write-set after this
30
    /// transaction's `begin_ts`. Caller should `ROLLBACK` (already
31
    /// implicitly performed) and retry the transaction with a
32
    /// fresh `begin_ts`.
33
    #[error("Busy: {0}")]
34
    Busy(String),
35
    /// Phase 11.4 — same shape as [`SQLRiteError::Busy`] but
36
    /// surfaces the snapshot-isolation specific case: a row in
37
    /// the read-set changed under us. Distinguished from `Busy`
38
    /// so SDKs can map it to a per-language exception that the
39
    /// caller's retry helper recognizes (mirrors Turso /
40
    /// libSQL's `BUSY` vs `BUSY_SNAPSHOT` split). v0 only emits
41
    /// `Busy` from the write-write validation loop; the
42
    /// read-anomaly variant is reserved for the snapshot-read
43
    /// integration that follows.
44
    #[error("BusySnapshot: {0}")]
45
    BusySnapshot(String),
46
}
47

48
// `std::io::Error` has no `PartialEq`, so we implement one by value-of-message.
49
// Used by existing tests that compare error variants.
50
impl PartialEq for SQLRiteError {
×
51
    fn eq(&self, other: &Self) -> bool {
1✔
52
        use SQLRiteError::*;
53
        match (self, other) {
1✔
54
            (NotImplemented(a), NotImplemented(b)) => a == b,
×
55
            (General(a), General(b)) => a == b,
1✔
56
            (Internal(a), Internal(b)) => a == b,
×
57
            (UnknownCommand(a), UnknownCommand(b)) => a == b,
×
58
            (SqlError(a), SqlError(b)) => format!("{a:?}") == format!("{b:?}"),
×
59
            (Io(a), Io(b)) => a.kind() == b.kind() && a.to_string() == b.to_string(),
×
60
            (Busy(a), Busy(b)) => a == b,
×
61
            (BusySnapshot(a), BusySnapshot(b)) => a == b,
×
62
            _ => false,
×
63
        }
64
    }
65
}
66

67
impl SQLRiteError {
68
    /// Phase 11.4 — true for `Busy` and `BusySnapshot`. SDK retry
69
    /// helpers branch on this rather than matching the variants
70
    /// individually so adding a third "retryable" variant later
71
    /// doesn't break callers.
72
    pub fn is_retryable(&self) -> bool {
1✔
73
        matches!(self, SQLRiteError::Busy(_) | SQLRiteError::BusySnapshot(_))
1✔
74
    }
75
}
76

77
/// Returns SQLRiteError::General error from String
78
#[allow(dead_code)]
×
79
pub fn sqlrite_error(message: &str) -> SQLRiteError {
1✔
80
    SQLRiteError::General(message.to_owned())
1✔
81
}
82

83
#[cfg(test)]
×
84
mod tests {
85
    use super::*;
86

87
    #[test]
×
88
    fn sqlrite_error_test() {
3✔
89
        let input = String::from("test error");
1✔
90
        let expected = SQLRiteError::General("test error".to_string());
2✔
91

92
        let result = sqlrite_error(&input);
2✔
93
        assert_eq!(result, expected);
2✔
94
    }
95

96
    #[test]
×
97
    fn sqlrite_display_not_implemented_test() {
3✔
98
        let error_string = String::from("Feature not implemented.");
1✔
99
        let input = SQLRiteError::NotImplemented(error_string.clone());
2✔
100

101
        let expected = format!("Not Implemented error: {}", error_string);
2✔
102
        let result = format!("{}", input);
2✔
103
        assert_eq!(result, expected);
2✔
104
    }
105

106
    #[test]
×
107
    fn sqlrite_display_general_test() {
3✔
108
        let error_string = String::from("General error.");
1✔
109
        let input = SQLRiteError::General(error_string.clone());
2✔
110

111
        let expected = format!("General error: {}", error_string);
2✔
112
        let result = format!("{}", input);
2✔
113
        assert_eq!(result, expected);
2✔
114
    }
115

116
    #[test]
×
117
    fn sqlrite_display_internal_test() {
3✔
118
        let error_string = String::from("Internet error.");
1✔
119
        let input = SQLRiteError::Internal(error_string.clone());
2✔
120

121
        let expected = format!("Internal error: {}", error_string);
2✔
122
        let result = format!("{}", input);
2✔
123
        assert_eq!(result, expected);
2✔
124
    }
125

126
    #[test]
×
127
    fn sqlrite_display_sqlrite_test() {
3✔
128
        let error_string = String::from("SQL error.");
1✔
129
        let input = SQLRiteError::SqlError(ParserError::ParserError(error_string.clone()));
2✔
130

131
        let expected = format!("SQL error: ParserError(\"{}\")", error_string);
2✔
132
        let result = format!("{}", input);
2✔
133
        assert_eq!(result, expected);
2✔
134
    }
135

136
    #[test]
×
137
    fn sqlrite_unknown_test() {
3✔
138
        let error_string = String::from("Unknown error.");
1✔
139
        let input = SQLRiteError::UnknownCommand(error_string.clone());
2✔
140

141
        let expected = format!("Unknown command error: {}", error_string);
2✔
142
        let result = format!("{}", input);
2✔
143
        assert_eq!(result, expected);
2✔
144
    }
145
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc