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    event_cache::EventCacheError, paginators::PaginatorError, room::reply::ReplyError,
17    send_queue::RoomSendQueueError, HttpError,
18};
19use thiserror::Error;
20
21use crate::timeline::{pinned_events_loader::PinnedEventsLoaderError, 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 reaction could not be toggled.
48    #[error("Failed toggling reaction")]
49    FailedToToggleReaction,
50
51    /// Couldn't read the encryption state of the room.
52    #[error("The room's encryption state is unknown.")]
53    UnknownEncryptionState,
54
55    /// Something went wrong with the room event cache.
56    #[error(transparent)]
57    EventCacheError(#[from] EventCacheError),
58
59    /// An error happened during pagination.
60    #[error(transparent)]
61    PaginationError(#[from] PaginationError),
62
63    /// An error happened during pagination.
64    #[error(transparent)]
65    PinnedEventsError(#[from] PinnedEventsLoaderError),
66
67    /// An error happened while operating the room's send queue.
68    #[error(transparent)]
69    SendQueueError(#[from] RoomSendQueueError),
70
71    /// An error happened while attempting to edit an event.
72    #[error(transparent)]
73    EditError(#[from] EditError),
74
75    /// An error happened while attempting to reply to an event.
76    #[error(transparent)]
77    ReplyError(#[from] ReplyError),
78
79    /// An error happened while attempting to redact an event.
80    #[error(transparent)]
81    RedactError(#[from] RedactError),
82}
83
84#[derive(Error, Debug)]
85pub enum EditError {
86    /// The content types have changed.
87    #[error("the new content type ({new}) doesn't match that of the previous content ({original}")]
88    ContentMismatch { original: String, new: String },
89
90    /// The local echo we tried to edit has been lost.
91    #[error("Invalid state: the local echo we tried to abort has been lost.")]
92    InvalidLocalEchoState,
93
94    /// An error happened at a lower level.
95    #[error(transparent)]
96    RoomError(#[from] matrix_sdk::room::edit::EditError),
97}
98
99#[derive(Error, Debug)]
100pub enum RedactError {
101    /// Local event to redact wasn't found for transaction id
102    #[error("Event to redact wasn't found for item id {0:?}")]
103    ItemNotFound(TimelineEventItemId),
104
105    /// An error happened while attempting to redact an event.
106    #[error(transparent)]
107    HttpError(#[from] HttpError),
108
109    /// The local echo we tried to abort has been lost.
110    #[error("Invalid state: the local echo we tried to abort has been lost.")]
111    InvalidLocalEchoState,
112}
113
114#[derive(Error, Debug)]
115pub enum PaginationError {
116    /// An error occurred while paginating.
117    #[error("Error when paginating.")]
118    Paginator(#[source] PaginatorError),
119
120    #[error("Pagination type not supported in this focus mode")]
121    NotSupported,
122}
123
124#[derive(Debug, Error)]
125pub enum UnsupportedEditItem {
126    #[error("tried to edit a non-poll event")]
127    NotPollEvent,
128    #[error("tried to edit another user's event")]
129    NotOwnEvent,
130    #[error("event to edit not found")]
131    MissingEvent,
132}
133
134#[derive(Debug, Error)]
135pub enum SendEventError {
136    #[error(transparent)]
137    UnsupportedEditItem(#[from] UnsupportedEditItem),
138
139    #[error(transparent)]
140    RoomQueueError(#[from] RoomSendQueueError),
141}