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