-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy patherror.rs
94 lines (82 loc) · 2.29 KB
/
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2024 RisingLight Project Authors. Licensed under Apache-2.0.
use std::sync::Arc;
use crate::catalog::CatalogError;
use crate::storage::TracedStorageError;
use crate::types::ConvertError;
/// The result type of execution.
pub type Result<T> = std::result::Result<T, Error>;
/// The error type of execution.
#[derive(thiserror::Error, Debug, Clone)]
#[error(transparent)]
pub struct Error {
inner: Arc<Inner>,
}
#[derive(thiserror::Error, Debug)]
enum Inner {
#[error("storage error: {0}")]
Storage(
#[from]
#[backtrace]
TracedStorageError,
),
#[error("catalog error: {0}")]
Catalog(#[from] CatalogError),
#[error("conversion error: {0}")]
Convert(#[from] ConvertError),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("csv error: {0}")]
Csv(#[from] csv::Error),
#[error("tuple length mismatch: expected {expected} but got {actual}")]
LengthMismatch { expected: usize, actual: usize },
#[error("exceed char/varchar length limit: item length {length} > char/varchar width {width}")]
ExceedLengthLimit { length: u64, width: u64 },
#[error("value can not be null")]
NotNullable,
#[error("abort")]
Aborted,
}
impl From<Inner> for Error {
fn from(e: Inner) -> Self {
Error { inner: Arc::new(e) }
}
}
impl From<TracedStorageError> for Error {
fn from(e: TracedStorageError) -> Self {
Inner::from(e).into()
}
}
impl From<CatalogError> for Error {
fn from(e: CatalogError) -> Self {
Inner::from(e).into()
}
}
impl From<ConvertError> for Error {
fn from(e: ConvertError) -> Self {
Inner::from(e).into()
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Inner::from(e).into()
}
}
impl From<csv::Error> for Error {
fn from(e: csv::Error) -> Self {
Inner::from(e).into()
}
}
impl Error {
pub fn length_mismatch(expected: usize, actual: usize) -> Self {
Inner::LengthMismatch { expected, actual }.into()
}
pub fn not_nullable() -> Self {
Inner::NotNullable.into()
}
pub fn exceed_length_limit(length: u64, width: u64) -> Self {
Inner::ExceedLengthLimit { length, width }.into()
}
pub fn aborted() -> Self {
Inner::Aborted.into()
}
}