-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
lib.rs
249 lines (210 loc) Β· 6.33 KB
/
lib.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#![feature(in_band_lifetimes)]
#![feature(specialization)]
#![feature(test)]
#![feature(backtrace)]
#![feature(async_closure)]
#![feature(drain_filter)]
// #![feature(trace_macros)]
// trace_macros!(true);
#[macro_use]
extern crate lazy_static;
use flexbuffers::DeserializationError;
use sqlparser::parser::ParserError;
use parquet::errors::ParquetError;
use tokio::sync::mpsc::error::SendError;
use std::backtrace::Backtrace;
use core::fmt;
use smallvec::alloc::fmt::{Formatter, Debug};
use arrow::error::ArrowError;
use serde_derive::{Deserialize, Serialize};
pub mod http;
pub mod remotefs;
pub mod table;
pub mod metastore;
pub mod sql;
pub mod mysql;
pub mod store;
pub mod scheduler;
pub mod cluster;
pub mod queryplanner;
pub mod import;
pub mod config;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CubeError {
message: String,
cause: CubeErrorCauseType
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CubeErrorCauseType {
User,
Internal
}
impl CubeError {
fn user(message: String) -> CubeError {
CubeError {
message, cause: CubeErrorCauseType::User
}
}
fn internal(message: String) -> CubeError {
CubeError {
message, cause: CubeErrorCauseType::Internal
}
}
fn from_error<E: fmt::Display>(error: E) -> CubeError {
CubeError {
message: format!("{}\n{}", error, Backtrace::capture()),
cause: CubeErrorCauseType::Internal
}
}
fn from_debug_error<E: Debug>(error: E) -> CubeError {
CubeError {
message: format!("{:?}\n{}", error, Backtrace::capture()),
cause: CubeErrorCauseType::Internal
}
}
}
impl fmt::Display for CubeError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_fmt(format_args!("{:?}: {}", self.cause, self.message))
}
}
impl From<flexbuffers::DeserializationError> for CubeError {
fn from(v: DeserializationError) -> Self {
CubeError::internal(v.to_string())
}
}
impl From<rocksdb::Error> for CubeError {
fn from(v: rocksdb::Error) -> Self {
CubeError::internal(v.into_string())
}
}
impl From<std::io::Error> for CubeError {
fn from(v: std::io::Error) -> Self {
CubeError::internal(format!("{:?}\n{}", v, Backtrace::capture()))
}
}
impl From<ParserError> for CubeError {
fn from(v: ParserError) -> Self {
CubeError::internal(format!("{:?}", v))
}
}
impl From<CubeError> for warp::reject::Rejection {
fn from(_: CubeError) -> Self { // TODO
warp::reject()
}
}
impl From<ParquetError> for CubeError {
fn from(v: ParquetError) -> Self {
CubeError::internal(v.to_string())
}
}
impl From<tokio::task::JoinError> for CubeError {
fn from(v: tokio::task::JoinError) -> Self {
CubeError::internal(v.to_string())
}
}
impl From<SendError<metastore::MetaStoreEvent>> for CubeError {
fn from(v: SendError<metastore::MetaStoreEvent>) -> Self {
CubeError::internal(format!("{:?}\n{}", v, Backtrace::capture()))
}
}
impl From<std::time::SystemTimeError> for CubeError {
fn from(v: std::time::SystemTimeError) -> Self {
CubeError::internal(v.to_string())
}
}
impl From<tokio::time::Elapsed> for CubeError {
fn from(v: tokio::time::Elapsed) -> Self {
CubeError::internal(v.to_string())
}
}
impl From<datafusion::error::DataFusionError> for CubeError {
fn from(v: datafusion::error::DataFusionError) -> Self {
CubeError::from_error(v)
}
}
impl From<CubeError> for datafusion::error::DataFusionError {
fn from(v: CubeError) -> Self {
datafusion::error::DataFusionError::Execution(v.to_string())
}
}
impl From<arrow::error::ArrowError> for CubeError {
fn from(v: ArrowError) -> Self {
CubeError::internal(v.to_string())
}
}
impl From<tokio::sync::broadcast::RecvError> for CubeError {
fn from(v: tokio::sync::broadcast::RecvError) -> Self {
CubeError::internal(format!("{:?}\n{}", v, Backtrace::capture()))
}
}
impl From<tokio::sync::broadcast::SendError<metastore::MetaStoreEvent>> for CubeError {
fn from(v: tokio::sync::broadcast::SendError<metastore::MetaStoreEvent>) -> Self {
CubeError::internal(format!("{:?}\n{}", v, Backtrace::capture()))
}
}
impl From<tokio::sync::broadcast::SendError<cluster::JobEvent>> for CubeError {
fn from(v: tokio::sync::broadcast::SendError<cluster::JobEvent>) -> Self {
CubeError::internal(format!("{:?}\n{}", v, Backtrace::capture()))
}
}
impl From<bigdecimal::ParseBigDecimalError> for CubeError {
fn from(v: bigdecimal::ParseBigDecimalError) -> Self {
CubeError::internal(v.to_string())
}
}
impl From<flexbuffers::SerializationError> for CubeError {
fn from(v: flexbuffers::SerializationError) -> Self {
CubeError::internal(v.to_string())
}
}
impl From<s3::S3Error> for CubeError {
fn from(v: s3::S3Error) -> Self {
CubeError::internal(v.to_string())
}
}
impl From<awscreds::AwsCredsError> for CubeError {
fn from(v: awscreds::AwsCredsError) -> Self {
CubeError::user(v.to_string())
}
}
impl From<awsregion::AwsRegionError> for CubeError {
fn from(v: awsregion::AwsRegionError) -> Self {
CubeError::user(v.to_string())
}
}
impl From<chrono::ParseError> for CubeError {
fn from(v: chrono::ParseError) -> Self {
CubeError::internal(v.to_string())
}
}
impl From<std::string::FromUtf8Error> for CubeError {
fn from(v: std::string::FromUtf8Error) -> Self {
CubeError::internal(v.to_string())
}
}
impl From<procspawn::SpawnError> for CubeError {
fn from(v: procspawn::SpawnError) -> Self {
CubeError::internal(v.to_string())
}
}
impl From<tokio::sync::oneshot::error::RecvError> for CubeError {
fn from(v: tokio::sync::oneshot::error::RecvError) -> Self {
CubeError::from_error(v)
}
}
impl From<ipc_channel::ipc::IpcError> for CubeError {
fn from(v: ipc_channel::ipc::IpcError) -> Self {
CubeError::from_debug_error(v)
}
}
impl From<Box<bincode::ErrorKind>> for CubeError {
fn from(v: Box<bincode::ErrorKind>) -> Self {
CubeError::from_debug_error(v)
}
}
impl From<tokio::sync::watch::error::SendError<bool>> for CubeError {
fn from(v: tokio::sync::watch::error::SendError<bool>) -> Self {
CubeError::from_error(v)
}
}