clickhouse_srv/protocols/
protocol_exception.rs

1use crate::binary::Encoder;
2use crate::error_codes::UNKNOWN_EXCEPTION;
3use crate::errors::Error;
4use crate::protocols::*;
5
6pub struct ExceptionResponse {}
7
8impl ExceptionResponse {
9    pub fn write(encoder: &mut Encoder, error: &Error, with_stack_trace: bool) {
10        let mut code = UNKNOWN_EXCEPTION;
11        let name = error.exception_name();
12        let mut stack_trace = "".to_string();
13        let mut message = error.to_string();
14
15        if let Error::Server(e) = error {
16            code = e.code;
17            if with_stack_trace {
18                stack_trace = e.stack_trace.clone();
19            }
20            message = e.message.clone();
21        }
22        encoder.uvarint(SERVER_EXCEPTION);
23
24        encoder.write(code);
25        //Name
26        encoder.string(name);
27        // Message
28        encoder.string(message);
29        // StackTrace
30        encoder.string(stack_trace);
31        // Nested.
32        encoder.write(false);
33    }
34}