trino_rust_client/models/
error.rs1use std::fmt;
2
3use serde::Deserialize;
4
5#[derive(Deserialize, Debug)]
6#[serde(rename_all = "camelCase")]
7pub struct QueryError {
8 pub message: String,
9 pub sql_state: Option<String>,
10 pub error_code: i32,
11 pub error_name: String,
12 pub error_type: String,
13 pub error_location: Option<ErrorLocation>,
14 pub failure_info: FailureInfo,
15}
16
17#[derive(Deserialize, Debug)]
18#[serde(rename_all = "camelCase")]
19pub struct ErrorLocation {
20 pub line_number: u32,
21 pub column_number: u32,
22}
23
24#[derive(Deserialize, Debug)]
25#[serde(rename_all = "camelCase")]
26pub struct FailureInfo {
27 #[serde(rename = "type")]
28 pub ty: String,
29 pub suppressed: Vec<FailureInfo>,
30 pub stack: Vec<String>,
31 pub message: Option<String>,
32 pub cause: Option<Box<FailureInfo>>,
33 pub error_location: Option<ErrorLocation>,
34}
35
36impl fmt::Display for QueryError {
37 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
38 writeln!(f, "message: {}", self.message)?;
39 if let Some(st) = &self.sql_state {
40 writeln!(f, "sql_state: {}", st)?;
41 }
42 writeln!(f, "error_code: {}", self.error_code)?;
43 writeln!(f, "error_type: {}", self.error_name)?;
44 if let Some(loc) = &self.error_location {
45 writeln!(f, "error_location: {}", loc)?;
46 }
47 writeln!(f, "failure_info: {}", self.failure_info)
48 }
49}
50
51impl std::error::Error for QueryError {}
52
53impl fmt::Display for ErrorLocation {
54 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
55 write!(f, "({}, {})", self.line_number, self.column_number)
56 }
57}
58
59impl fmt::Display for FailureInfo {
60 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
61 writeln!(f, "ty: {}", self.ty)?;
62 if let Some(msg) = &self.message {
63 writeln!(f, "message: {}", msg)?;
64 }
65 if let Some(loc) = &self.error_location {
66 writeln!(f, "loc: {}", loc)?;
67 }
68 writeln!(f, "stack:")?;
69 for s in &self.stack {
70 writeln!(f, "\ttype: {}", s)?;
71 }
72 if let Some(cause) = &self.cause {
73 writeln!(f, "cause: {}", cause)?;
74 }
75 Ok(())
76 }
77}
78
79#[cfg(test)]
80mod tests {
81 use super::*;
82
83 #[test]
84 fn test_loc() {
85 let loc = ErrorLocation {
86 line_number: 100,
87 column_number: 15,
88 };
89
90 assert_eq!("(100, 15)", format!("{}", loc));
91 }
92
93 #[test]
94 fn test_failure() {
95 let failure = FailureInfo {
96 ty: "xxxty".into(),
97 suppressed: vec![],
98 stack: vec!["stack_1".into(), "stack_2".into(), "stack_3".into()],
99 message: None,
100 cause: None,
101 error_location: None,
102 };
103
104 println!("{}", failure);
105 }
106}