matrix_sdk_search/
error.rs

1// Copyright 2024 The Matrix.org Foundation C.I.C.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use tantivy::{
16    directory::error::OpenDirectoryError as TantivyOpenDirectoryError,
17    query::QueryParserError as TantivyQueryParserError,
18};
19use thiserror::Error;
20
21/// Internal representation of Search Index errors.
22#[derive(Error, Debug)]
23pub enum IndexError {
24    /// Tantivy Error
25    #[error(transparent)]
26    TantivyError(tantivy::TantivyError),
27
28    /// Open Directory Error
29    #[error(transparent)]
30    OpenDirectoryError(TantivyOpenDirectoryError),
31
32    /// Query Parse Error
33    #[error(transparent)]
34    QueryParserError(TantivyQueryParserError),
35
36    /// Schema Error
37    #[error(transparent)]
38    IndexSchemaError(IndexSchemaError),
39
40    /// Write Error
41    #[error(transparent)]
42    IndexWriteError(IndexWriteError),
43
44    /// Message Type Error
45    #[error("Message type not supported")]
46    MessageTypeNotSupported,
47
48    /// Indexing Redacted Message Error
49    #[error("Cannot index redacted message")]
50    CannotIndexRedactedMessage,
51
52    /// Indexing Empty Message Error
53    #[error("Cannot index empty message")]
54    EmptyMessage,
55
56    /// IO error
57    #[error(transparent)]
58    IO(std::io::Error),
59}
60
61impl From<tantivy::TantivyError> for IndexError {
62    fn from(err: tantivy::TantivyError) -> IndexError {
63        IndexError::TantivyError(err)
64    }
65}
66
67impl From<TantivyOpenDirectoryError> for IndexError {
68    fn from(err: TantivyOpenDirectoryError) -> IndexError {
69        IndexError::OpenDirectoryError(err)
70    }
71}
72
73impl From<TantivyQueryParserError> for IndexError {
74    fn from(err: TantivyQueryParserError) -> IndexError {
75        IndexError::QueryParserError(err)
76    }
77}
78
79impl From<IndexSchemaError> for IndexError {
80    fn from(err: IndexSchemaError) -> IndexError {
81        IndexError::IndexSchemaError(err)
82    }
83}
84
85impl From<IndexWriteError> for IndexError {
86    fn from(err: IndexWriteError) -> IndexError {
87        IndexError::IndexWriteError(err)
88    }
89}
90
91impl From<std::io::Error> for IndexError {
92    fn from(err: std::io::Error) -> IndexError {
93        IndexError::IO(err)
94    }
95}
96
97/// Internal representation of Schema errors.
98#[derive(Error, Debug)]
99pub enum IndexSchemaError {
100    /// Tantivy Error
101    #[error(transparent)]
102    TantivyError(tantivy::TantivyError),
103}
104
105impl From<tantivy::TantivyError> for IndexSchemaError {
106    fn from(err: tantivy::TantivyError) -> IndexSchemaError {
107        IndexSchemaError::TantivyError(err)
108    }
109}
110
111/// Internal representation of Writer errors.
112#[derive(Error, Debug)]
113pub enum IndexWriteError {
114    /// Tantivy Error
115    #[error(transparent)]
116    TantivyError(tantivy::TantivyError),
117}
118
119impl From<tantivy::TantivyError> for IndexWriteError {
120    fn from(err: tantivy::TantivyError) -> IndexWriteError {
121        IndexWriteError::TantivyError(err)
122    }
123}