index/fulltext_index/
error.rs1use std::any::Any;
16use std::io::Error as IoError;
17
18use common_error::ext::{BoxedError, ErrorExt};
19use common_error::status_code::StatusCode;
20use common_macro::stack_trace_debug;
21use snafu::{Location, Snafu};
22use tantivy::DocAddress;
23
24#[derive(Snafu)]
25#[snafu(visibility(pub))]
26#[stack_trace_debug]
27pub enum Error {
28 #[snafu(display("IO error"))]
29 Io {
30 #[snafu(source)]
31 error: IoError,
32 #[snafu(implicit)]
33 location: Location,
34 },
35
36 #[snafu(display("Tantivy error"))]
37 Tantivy {
38 #[snafu(source)]
39 error: tantivy::TantivyError,
40 #[snafu(implicit)]
41 location: Location,
42 },
43
44 #[snafu(display("Tantivy parser error"))]
45 TantivyParser {
46 #[snafu(source)]
47 error: tantivy::query::QueryParserError,
48 #[snafu(implicit)]
49 location: Location,
50 },
51
52 #[snafu(display("Tantivy doc not found"))]
53 TantivyDocNotFound {
54 #[snafu(implicit)]
55 location: Location,
56 doc_addr: DocAddress,
57 },
58
59 #[snafu(display("Operate on a finished creator"))]
60 Finished {
61 #[snafu(implicit)]
62 location: Location,
63 },
64
65 #[snafu(display("External error"))]
66 External {
67 source: BoxedError,
68 #[snafu(implicit)]
69 location: Location,
70 },
71
72 #[snafu(display("Join error"))]
73 Join {
74 #[snafu(source)]
75 error: tokio::task::JoinError,
76 #[snafu(implicit)]
77 location: Location,
78 },
79
80 #[snafu(display("Aborted creator"))]
81 Aborted {
82 #[snafu(implicit)]
83 location: Location,
84 },
85
86 #[snafu(display("Failed to add blob to puffin file"))]
87 PuffinAddBlob {
88 source: puffin::error::Error,
89 #[snafu(implicit)]
90 location: Location,
91 },
92
93 #[snafu(display("Failed to finish bloom filter"))]
94 BloomFilterFinish {
95 source: crate::bloom_filter::error::Error,
96 #[snafu(implicit)]
97 location: Location,
98 },
99
100 #[snafu(display("BiErrors, first: {first}, second: {second}"))]
101 BiErrors {
102 first: Box<Error>,
103 second: Box<Error>,
104 #[snafu(implicit)]
105 location: Location,
106 },
107
108 #[snafu(display("Failed to serialize to json"))]
109 SerializeToJson {
110 #[snafu(source)]
111 error: serde_json::error::Error,
112 #[snafu(implicit)]
113 location: Location,
114 },
115
116 #[snafu(display("Failed to deserialize from json"))]
117 DeserializeFromJson {
118 #[snafu(source)]
119 error: serde_json::error::Error,
120 #[snafu(implicit)]
121 location: Location,
122 },
123}
124
125impl ErrorExt for Error {
126 fn status_code(&self) -> StatusCode {
127 use Error::*;
128
129 match self {
130 Tantivy { .. } | TantivyDocNotFound { .. } => StatusCode::Internal,
131 TantivyParser { .. } => StatusCode::InvalidSyntax,
132
133 BiErrors { .. } => StatusCode::Internal,
134
135 Io { .. } | Finished { .. } | Join { .. } | Aborted { .. } => StatusCode::Unexpected,
136
137 BloomFilterFinish { source, .. } => source.status_code(),
138 PuffinAddBlob { source, .. } => source.status_code(),
139
140 External { source, .. } => source.status_code(),
141
142 SerializeToJson { .. } | DeserializeFromJson { .. } => StatusCode::Internal,
143 }
144 }
145
146 fn as_any(&self) -> &dyn Any {
147 self
148 }
149}
150
151pub type Result<T> = std::result::Result<T, Error>;