Skip to main content

matrix_sdk_ui/timeline/
error.rs

1// Copyright 2023 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 matrix_sdk::{
16    HttpError, event_cache::EventCacheError, paginators::PaginatorError, room::reply::ReplyError,
17    send_queue::RoomSendQueueError,
18};
19use thiserror::Error;
20
21use crate::timeline::TimelineEventItemId;
22
23/// Errors specific to the timeline.
24#[derive(Error, Debug)]
25#[non_exhaustive]
26pub enum Error {
27    /// The requested event is not in the timeline.
28    #[error("Event not found in timeline: {0:?}")]
29    EventNotInTimeline(TimelineEventItemId),
30
31    /// The event is currently unsupported for this use case..
32    #[error("Unsupported event")]
33    UnsupportedEvent,
34
35    /// Couldn't read the attachment data from the given URL.
36    #[error("Invalid attachment data")]
37    InvalidAttachmentData,
38
39    /// The attachment file name used as a body is invalid.
40    #[error("Invalid attachment file name")]
41    InvalidAttachmentFileName,
42
43    /// The attachment could not be sent.
44    #[error("Failed sending attachment")]
45    FailedSendingAttachment,
46
47    /// The redaction could not be sent.
48    #[error("Failed sending redaction")]
49    FailedSendingRedaction,
50
51    /// The reaction could not be toggled.
52    #[error("Failed toggling reaction")]
53    FailedToToggleReaction,
54
55    /// Couldn't read the encryption state of the room.
56    #[error("The room's encryption state is unknown.")]
57    UnknownEncryptionState,
58
59    /// An error from the underlying Matrix SDK.
60    #[error(transparent)]
61    Sdk(#[from] matrix_sdk::Error),
62
63    /// Something went wrong with the room event cache.
64    #[error(transparent)]
65    EventCacheError(#[from] EventCacheError),
66
67    /// An error happened during pagination.
68    #[error(transparent)]
69    PaginationError(#[from] PaginationError),
70
71    /// An error happened while operating the room's send queue.
72    #[error(transparent)]
73    SendQueueError(#[from] RoomSendQueueError),
74
75    /// An error happened while attempting to edit an event.
76    #[error(transparent)]
77    EditError(#[from] EditError),
78
79    /// An error happened while attempting to reply to an event.
80    #[error(transparent)]
81    ReplyError(#[from] ReplyError),
82
83    /// An error happened while attempting to redact an event.
84    #[error(transparent)]
85    RedactError(#[from] RedactError),
86}
87
88#[derive(Error, Debug)]
89pub enum EditError {
90    /// The content types have changed.
91    #[error("the new content type ({new}) doesn't match that of the previous content ({original}")]
92    ContentMismatch { original: String, new: String },
93
94    /// The local echo we tried to edit has been lost.
95    #[error("Invalid state: the local echo we tried to abort has been lost.")]
96    InvalidLocalEchoState,
97
98    /// An error happened at a lower level.
99    #[error(transparent)]
100    RoomError(#[from] matrix_sdk::room::edit::EditError),
101}
102
103#[derive(Error, Debug)]
104pub enum RedactError {
105    /// Local event to redact wasn't found for transaction id
106    #[error("Event to redact wasn't found for item id {0:?}")]
107    ItemNotFound(TimelineEventItemId),
108
109    /// An error happened while attempting to redact an event.
110    #[error(transparent)]
111    HttpError(#[from] HttpError),
112
113    /// The local echo we tried to abort has been lost.
114    #[error("Invalid state: the local echo we tried to abort has been lost.")]
115    InvalidLocalEchoState,
116}
117
118#[derive(Error, Debug)]
119pub enum PaginationError {
120    /// An error occurred while paginating.
121    #[error("Error when paginating: {0}")]
122    Pagination(#[from] PaginatorError),
123
124    /// An error occurred in the event cache.
125    #[error("Error in event cache.")]
126    EventCache(#[source] EventCacheError),
127
128    /// The focused event doesn't have an attached cache.
129    #[error("Missing cache for focused event")]
130    MissingCache,
131
132    #[error("Pagination type not supported in this focus mode")]
133    NotSupported,
134}
135
136#[derive(Debug, Error)]
137pub enum UnsupportedEditItem {
138    #[error("tried to edit a non-poll event")]
139    NotPollEvent,
140    #[error("tried to edit another user's event")]
141    NotOwnEvent,
142    #[error("event to edit not found")]
143    MissingEvent,
144}
145
146#[derive(Debug, Error)]
147pub enum SendEventError {
148    #[error(transparent)]
149    UnsupportedEditItem(#[from] UnsupportedEditItem),
150
151    #[error(transparent)]
152    RoomQueueError(#[from] RoomSendQueueError),
153}