use matrix_sdk::{
event_cache::{paginator::PaginatorError, EventCacheError},
send_queue::RoomSendQueueError,
HttpError,
};
use thiserror::Error;
use crate::timeline::{pinned_events_loader::PinnedEventsLoaderError, TimelineEventItemId};
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error("Event not found in timeline: {0:?}")]
EventNotInTimeline(TimelineEventItemId),
#[error("Unsupported event")]
UnsupportedEvent,
#[error("Invalid attachment data")]
InvalidAttachmentData,
#[error("Invalid attachment file name")]
InvalidAttachmentFileName,
#[error("Failed sending attachment")]
FailedSendingAttachment,
#[error("Failed toggling reaction")]
FailedToToggleReaction,
#[error("The room's encryption state is unknown.")]
UnknownEncryptionState,
#[error("Something went wrong with the room event cache.")]
EventCacheError(#[from] EventCacheError),
#[error("An error happened during pagination.")]
PaginationError(#[from] PaginationError),
#[error("An error happened when loading pinned events.")]
PinnedEventsError(#[from] PinnedEventsLoaderError),
#[error(transparent)]
SendQueueError(#[from] RoomSendQueueError),
#[error(transparent)]
EditError(#[from] EditError),
#[error(transparent)]
RedactError(#[from] RedactError),
}
#[derive(Error, Debug)]
pub enum EditError {
#[error("the new content type ({new}) doesn't match that of the previous content ({original}")]
ContentMismatch { original: String, new: String },
#[error("Invalid state: the local echo we tried to abort has been lost.")]
InvalidLocalEchoState,
#[error(transparent)]
RoomError(#[from] matrix_sdk::room::edit::EditError),
}
#[derive(Error, Debug)]
pub enum RedactError {
#[error("Event to redact wasn't found for item id {0:?}")]
ItemNotFound(TimelineEventItemId),
#[error(transparent)]
HttpError(#[from] HttpError),
#[error("Invalid state: the local echo we tried to abort has been lost.")]
InvalidLocalEchoState,
}
#[derive(Error, Debug)]
pub enum PaginationError {
#[error("The timeline isn't in the event focus mode")]
NotEventFocusMode,
#[error("Error when paginating.")]
Paginator(#[source] PaginatorError),
}
#[derive(Debug, Error)]
pub enum UnsupportedReplyItem {
#[error("local messages whose event ID is not known can't be replied to currently")]
MissingEventId,
#[error("redacted events whose JSON form isn't available can't be replied")]
MissingJson,
#[error("event to reply to not found")]
MissingEvent,
#[error("failed to deserialize event to reply to")]
FailedToDeserializeEvent,
#[error("tried to reply to a state event")]
StateEvent,
}
#[derive(Debug, Error)]
pub enum UnsupportedEditItem {
#[error("tried to edit a non-poll event")]
NotPollEvent,
#[error("tried to edit another user's event")]
NotOwnEvent,
#[error("event to edit not found")]
MissingEvent,
}
#[derive(Debug, Error)]
pub enum SendEventError {
#[error(transparent)]
UnsupportedEditItem(#[from] UnsupportedEditItem),
#[error(transparent)]
RoomQueueError(#[from] RoomSendQueueError),
}