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
50pub type Result<T> = std::result::Result<T, Error>;
51
52impl ErrorExt for Error {
53 fn status_code(&self) -> StatusCode {
54 match self {
55 Error::MismatchedSchema { .. } | Error::SerializeEvent { .. } => {
56 StatusCode::InvalidArguments
57 }
58 Error::InsertEvents { .. } => StatusCode::Internal,
59 }
60 }
61
62 fn as_any(&self) -> &dyn std::any::Any {
63 self
64 }
65}