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