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
use thiserror::Error;
use crate::ColumnType;
#[derive(Debug, Error)]
pub enum FbError {
#[error("sql error {code}: {msg}")]
Sql { msg: String, code: i32 },
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("error: {0}")]
Other(String),
}
impl From<String> for FbError {
fn from(msg: String) -> Self {
Self::Other(msg)
}
}
impl From<&str> for FbError {
fn from(msg: &str) -> Self {
Self::Other(msg.to_string())
}
}
pub fn err_column_null(type_name: &str) -> FbError {
FbError::Other(format!(
"This is a null value. Use the Option<{}> to safe access this column and avoid errors",
type_name
))
}
pub fn err_type_conv<T>(from: ColumnType, to: &str) -> Result<T, FbError> {
Err(FbError::Other(format!(
"Can't convert {:?} column to {}",
from, to
)))
}