common_event_recorder/
error.rs1use api::v1::ColumnSchema;
16use common_error::ext::{BoxedError, ErrorExt};
17use common_error::status_code::StatusCode;
18use common_macro::stack_trace_debug;
19use snafu::{Location, Snafu};
20
21#[derive(Snafu)]
22#[snafu(visibility(pub))]
23#[stack_trace_debug]
24pub enum Error {
25 #[snafu(display("Mismatched schema, expected: {:?}, actual: {:?}", expected, actual))]
26 MismatchedSchema {
27 #[snafu(implicit)]
28 location: Location,
29 expected: Vec<ColumnSchema>,
30 actual: Vec<ColumnSchema>,
31 },
32
33 #[snafu(display("Failed to serialize event"))]
34 SerializeEvent {
35 #[snafu(source)]
36 error: serde_json::error::Error,
37 #[snafu(implicit)]
38 location: Location,
39 },
40
41 #[snafu(display("Failed to insert events"))]
42 InsertEvents {
43 source: BoxedError,
45 #[snafu(implicit)]
46 location: Location,
47 },
48
49 #[snafu(display("Keyvalue backend error"))]
50 KvBackend {
51 source: BoxedError,
53 #[snafu(implicit)]
54 location: Location,
55 },
56}
57
58pub type Result<T> = std::result::Result<T, Error>;
59
60impl ErrorExt for Error {
61 fn status_code(&self) -> StatusCode {
62 match self {
63 Error::MismatchedSchema { .. } | Error::SerializeEvent { .. } => {
64 StatusCode::InvalidArguments
65 }
66 Error::InsertEvents { .. } | Error::KvBackend { .. } => StatusCode::Internal,
67 }
68 }
69
70 fn as_any(&self) -> &dyn std::any::Any {
71 self
72 }
73}