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.
1415use matrix_sdk::{
16 event_cache::{paginator::PaginatorError, EventCacheError},
17 room::reply::ReplyError,
18 send_queue::RoomSendQueueError,
19 HttpError,
20};
21use thiserror::Error;
2223use crate::timeline::{pinned_events_loader::PinnedEventsLoaderError, TimelineEventItemId};
2425/// 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:?}")]
31EventNotInTimeline(TimelineEventItemId),
3233/// The event is currently unsupported for this use case..
34#[error("Unsupported event")]
35UnsupportedEvent,
3637/// Couldn't read the attachment data from the given URL.
38#[error("Invalid attachment data")]
39InvalidAttachmentData,
4041/// The attachment file name used as a body is invalid.
42#[error("Invalid attachment file name")]
43InvalidAttachmentFileName,
4445/// The attachment could not be sent.
46#[error("Failed sending attachment")]
47FailedSendingAttachment,
4849/// The reaction could not be toggled.
50#[error("Failed toggling reaction")]
51FailedToToggleReaction,
5253/// Couldn't read the encryption state of the room.
54#[error("The room's encryption state is unknown.")]
55UnknownEncryptionState,
5657/// Something went wrong with the room event cache.
58#[error(transparent)]
59EventCacheError(#[from] EventCacheError),
6061/// An error happened during pagination.
62#[error(transparent)]
63PaginationError(#[from] PaginationError),
6465/// An error happened during pagination.
66#[error(transparent)]
67PinnedEventsError(#[from] PinnedEventsLoaderError),
6869/// An error happened while operating the room's send queue.
70#[error(transparent)]
71SendQueueError(#[from] RoomSendQueueError),
7273/// An error happened while attempting to edit an event.
74#[error(transparent)]
75EditError(#[from] EditError),
7677/// An error happened while attempting to reply to an event.
78#[error(transparent)]
79ReplyError(#[from] ReplyError),
8081/// An error happened while attempting to redact an event.
82#[error(transparent)]
83RedactError(#[from] RedactError),
84}
8586#[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}")]
90ContentMismatch { original: String, new: String },
9192/// The local echo we tried to edit has been lost.
93#[error("Invalid state: the local echo we tried to abort has been lost.")]
94InvalidLocalEchoState,
9596/// An error happened at a lower level.
97#[error(transparent)]
98RoomError(#[from] matrix_sdk::room::edit::EditError),
99}
100101#[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:?}")]
105ItemNotFound(TimelineEventItemId),
106107/// An error happened while attempting to redact an event.
108#[error(transparent)]
109HttpError(#[from] HttpError),
110111/// The local echo we tried to abort has been lost.
112#[error("Invalid state: the local echo we tried to abort has been lost.")]
113InvalidLocalEchoState,
114}
115116#[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")]
120NotEventFocusMode,
121122/// An error occurred while paginating.
123#[error("Error when paginating.")]
124Paginator(#[source] PaginatorError),
125}
126127#[derive(Debug, Error)]
128pub enum UnsupportedEditItem {
129#[error("tried to edit a non-poll event")]
130NotPollEvent,
131#[error("tried to edit another user's event")]
132NotOwnEvent,
133#[error("event to edit not found")]
134MissingEvent,
135}
136137#[derive(Debug, Error)]
138pub enum SendEventError {
139#[error(transparent)]
140UnsupportedEditItem(#[from] UnsupportedEditItem),
141142#[error(transparent)]
143RoomQueueError(#[from] RoomSendQueueError),
144}