Skip to content

Commit a5ad1ea

Browse files
committed
Add error handling to and from protobuf messages
1 parent bd9e61f commit a5ad1ea

File tree

11 files changed

+1212
-1
lines changed

11 files changed

+1212
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ uuid = "1.17.0"
1919
delegate = "0.13.4"
2020
dashmap = "6.1.0"
2121
prost = "0.13.5"
22+
object_store = "0.12.3"
2223

2324
[dev-dependencies]
24-
insta = { version = "1.43.1" , features = ["filters"]}
25+
insta = { version = "1.43.1", features = ["filters"] }

src/errors/arrow_error.rs

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
use crate::errors::io_error::IoErrorProto;
2+
use datafusion::arrow::error::ArrowError;
3+
4+
#[derive(Clone, PartialEq, ::prost::Message)]
5+
pub struct ArrowErrorProto {
6+
#[prost(oneof = "ArrowErrorInnerProto", tags = "1")]
7+
pub inner: Option<ArrowErrorInnerProto>,
8+
#[prost(string, optional, tag = "2")]
9+
pub ctx: Option<String>,
10+
}
11+
12+
#[derive(Clone, PartialEq, prost::Oneof)]
13+
pub enum ArrowErrorInnerProto {
14+
#[prost(string, tag = "1")]
15+
NotYetImplemented(String),
16+
#[prost(string, tag = "2")]
17+
ExternalError(String),
18+
#[prost(string, tag = "3")]
19+
CastError(String),
20+
#[prost(string, tag = "4")]
21+
MemoryError(String),
22+
#[prost(string, tag = "5")]
23+
ParseError(String),
24+
#[prost(string, tag = "6")]
25+
SchemaError(String),
26+
#[prost(string, tag = "7")]
27+
ComputeError(String),
28+
#[prost(bool, tag = "8")]
29+
DivideByZero(bool),
30+
#[prost(string, tag = "9")]
31+
ArithmeticOverflow(String),
32+
#[prost(string, tag = "10")]
33+
CsvError(String),
34+
#[prost(string, tag = "11")]
35+
JsonError(String),
36+
#[prost(message, tag = "12")]
37+
IoError(IoErrorProto),
38+
#[prost(message, tag = "13")]
39+
IpcError(String),
40+
#[prost(message, tag = "14")]
41+
InvalidArgumentError(String),
42+
#[prost(message, tag = "15")]
43+
ParquetError(String),
44+
#[prost(message, tag = "16")]
45+
CDataInterface(String),
46+
#[prost(bool, tag = "17")]
47+
DictionaryKeyOverflowError(bool),
48+
#[prost(bool, tag = "18")]
49+
RunEndIndexOverflowError(bool),
50+
}
51+
52+
impl ArrowErrorProto {
53+
pub fn from_arrow_error(err: &ArrowError, ctx: Option<&String>) -> Self {
54+
match err {
55+
ArrowError::NotYetImplemented(msg) => ArrowErrorProto {
56+
inner: Some(ArrowErrorInnerProto::NotYetImplemented(msg.to_string())),
57+
ctx: ctx.cloned(),
58+
},
59+
ArrowError::ExternalError(msg) => ArrowErrorProto {
60+
inner: Some(ArrowErrorInnerProto::ExternalError(msg.to_string())),
61+
ctx: ctx.cloned(),
62+
},
63+
ArrowError::CastError(msg) => ArrowErrorProto {
64+
inner: Some(ArrowErrorInnerProto::CastError(msg.to_string())),
65+
ctx: ctx.cloned(),
66+
},
67+
ArrowError::MemoryError(msg) => ArrowErrorProto {
68+
inner: Some(ArrowErrorInnerProto::MemoryError(msg.to_string())),
69+
ctx: ctx.cloned(),
70+
},
71+
ArrowError::ParseError(msg) => ArrowErrorProto {
72+
inner: Some(ArrowErrorInnerProto::ParseError(msg.to_string())),
73+
ctx: ctx.cloned(),
74+
},
75+
ArrowError::SchemaError(msg) => ArrowErrorProto {
76+
inner: Some(ArrowErrorInnerProto::SchemaError(msg.to_string())),
77+
ctx: ctx.cloned(),
78+
},
79+
ArrowError::ComputeError(msg) => ArrowErrorProto {
80+
inner: Some(ArrowErrorInnerProto::ComputeError(msg.to_string())),
81+
ctx: ctx.cloned(),
82+
},
83+
ArrowError::DivideByZero => ArrowErrorProto {
84+
inner: Some(ArrowErrorInnerProto::DivideByZero(true)),
85+
ctx: ctx.cloned(),
86+
},
87+
ArrowError::ArithmeticOverflow(msg) => ArrowErrorProto {
88+
inner: Some(ArrowErrorInnerProto::ArithmeticOverflow(msg.to_string())),
89+
ctx: ctx.cloned(),
90+
},
91+
ArrowError::CsvError(msg) => ArrowErrorProto {
92+
inner: Some(ArrowErrorInnerProto::CsvError(msg.to_string())),
93+
ctx: ctx.cloned(),
94+
},
95+
ArrowError::JsonError(msg) => ArrowErrorProto {
96+
inner: Some(ArrowErrorInnerProto::JsonError(msg.to_string())),
97+
ctx: ctx.cloned(),
98+
},
99+
ArrowError::IoError(msg, err) => ArrowErrorProto {
100+
inner: Some(ArrowErrorInnerProto::IoError(IoErrorProto::from_io_error(
101+
msg, err,
102+
))),
103+
ctx: ctx.cloned(),
104+
},
105+
ArrowError::IpcError(msg) => ArrowErrorProto {
106+
inner: Some(ArrowErrorInnerProto::IpcError(msg.to_string())),
107+
ctx: ctx.cloned(),
108+
},
109+
ArrowError::InvalidArgumentError(msg) => ArrowErrorProto {
110+
inner: Some(ArrowErrorInnerProto::InvalidArgumentError(msg.to_string())),
111+
ctx: ctx.cloned(),
112+
},
113+
ArrowError::ParquetError(msg) => ArrowErrorProto {
114+
inner: Some(ArrowErrorInnerProto::ParquetError(msg.to_string())),
115+
ctx: ctx.cloned(),
116+
},
117+
ArrowError::CDataInterface(msg) => ArrowErrorProto {
118+
inner: Some(ArrowErrorInnerProto::CDataInterface(msg.to_string())),
119+
ctx: ctx.cloned(),
120+
},
121+
ArrowError::DictionaryKeyOverflowError => ArrowErrorProto {
122+
inner: Some(ArrowErrorInnerProto::DictionaryKeyOverflowError(true)),
123+
ctx: ctx.cloned(),
124+
},
125+
ArrowError::RunEndIndexOverflowError => ArrowErrorProto {
126+
inner: Some(ArrowErrorInnerProto::RunEndIndexOverflowError(true)),
127+
ctx: ctx.cloned(),
128+
},
129+
}
130+
}
131+
132+
pub fn to_arrow_error(&self) -> (ArrowError, Option<String>) {
133+
let Some(ref inner) = self.inner else {
134+
return (
135+
ArrowError::ExternalError(Box::from("Malformed protobuf message".to_string())),
136+
None,
137+
);
138+
};
139+
let err = match inner {
140+
ArrowErrorInnerProto::NotYetImplemented(msg) => {
141+
ArrowError::NotYetImplemented(msg.to_string())
142+
}
143+
ArrowErrorInnerProto::ExternalError(msg) => {
144+
ArrowError::ExternalError(Box::from(msg.to_string()))
145+
}
146+
ArrowErrorInnerProto::CastError(msg) => ArrowError::CastError(msg.to_string()),
147+
ArrowErrorInnerProto::MemoryError(msg) => ArrowError::MemoryError(msg.to_string()),
148+
ArrowErrorInnerProto::ParseError(msg) => ArrowError::ParseError(msg.to_string()),
149+
ArrowErrorInnerProto::SchemaError(msg) => ArrowError::SchemaError(msg.to_string()),
150+
ArrowErrorInnerProto::ComputeError(msg) => ArrowError::ComputeError(msg.to_string()),
151+
ArrowErrorInnerProto::DivideByZero(_) => ArrowError::DivideByZero,
152+
ArrowErrorInnerProto::ArithmeticOverflow(msg) => {
153+
ArrowError::ArithmeticOverflow(msg.to_string())
154+
}
155+
ArrowErrorInnerProto::CsvError(msg) => ArrowError::CsvError(msg.to_string()),
156+
ArrowErrorInnerProto::JsonError(msg) => ArrowError::JsonError(msg.to_string()),
157+
ArrowErrorInnerProto::IoError(msg) => {
158+
let (msg, err) = msg.to_io_error();
159+
ArrowError::IoError(err, msg)
160+
}
161+
ArrowErrorInnerProto::IpcError(msg) => ArrowError::IpcError(msg.to_string()),
162+
ArrowErrorInnerProto::InvalidArgumentError(msg) => {
163+
ArrowError::InvalidArgumentError(msg.to_string())
164+
}
165+
ArrowErrorInnerProto::ParquetError(msg) => ArrowError::ParquetError(msg.to_string()),
166+
ArrowErrorInnerProto::CDataInterface(msg) => {
167+
ArrowError::CDataInterface(msg.to_string())
168+
}
169+
ArrowErrorInnerProto::DictionaryKeyOverflowError(_) => {
170+
ArrowError::DictionaryKeyOverflowError
171+
}
172+
ArrowErrorInnerProto::RunEndIndexOverflowError(_) => {
173+
ArrowError::RunEndIndexOverflowError
174+
}
175+
};
176+
(err, self.ctx.clone())
177+
}
178+
}

0 commit comments

Comments
 (0)