use derive_more::IsVariant;
use smol_str::SmolStr;
use crate::domain::{
aggregates::{
chapter::ChapterError,
curation::{NilIdError, SceneAnnotationError},
media::MediaError,
speaker::SpeakerError,
watched_location::WatchedLocationError,
},
primitives::{LocationError, Uuid7Error},
};
#[cfg(feature = "audio")]
use crate::domain::aggregates::audio::{
segment::WordError, AudioError, AudioSegmentError, AudioTrackError,
};
#[cfg(feature = "subtitle")]
use crate::domain::aggregates::subtitle::{
cue::SubtitleCueError, facet::SubtitleError, track::SubtitleTrackError,
};
#[cfg(feature = "video")]
use crate::domain::aggregates::video::{
detections::DetectionError, facet::VideoError, keyframe::KeyframeError, scene::SceneError,
track::VideoTrackError,
};
#[derive(Debug, Clone, PartialEq, IsVariant, thiserror::Error)]
#[non_exhaustive]
pub enum MongoError {
#[error("missing required bson field `{0}`")]
MissingField(SmolStr),
#[error("field `{field}`: expected {want}, got {got}")]
TypeMismatch {
field: SmolStr,
want: &'static str,
got: &'static str,
},
#[error("field `{field}`: expected {want}-byte binary, got {got}")]
WrongBinaryLen {
field: SmolStr,
want: usize,
got: usize,
},
#[error("field `{field}`: integer value {value} out of range")]
IntOutOfRange { field: SmolStr, value: i64 },
#[error("Uuid7 decode failed: {0}")]
Uuid7(#[from] Uuid7Error),
#[error("Location decode failed: {0}")]
Location(#[from] LocationError),
#[error("Language decode failed: {0}")]
Language(#[from] ::mediaframe::lang::LanguageError),
#[error("GeoLocation decode failed: {0}")]
GeoLocation(#[from] ::mediaframe::capture::GeoLocationError),
#[error("audio Fingerprint decode failed: {0}")]
Fingerprint(#[from] ::mediaframe::audio::FingerprintError),
#[error("audio CoverArt decode failed: {0}")]
CoverArt(#[from] ::mediaframe::audio::CoverArtError),
#[error("Media try_new rejected: {0}")]
Media(#[from] MediaError),
#[error("Chapter try_new rejected: {0}")]
Chapter(#[from] ChapterError),
#[error("domain constructor rejected: {0}")]
DomainConstructorRejected(String),
#[error("WatchedLocation try_new rejected: {0}")]
WatchedLocation(#[from] WatchedLocationError),
#[error("Speaker try_new rejected: {0}")]
Speaker(#[from] SpeakerError),
#[error("id rejected: {0}")]
NilId(#[from] NilIdError),
#[error("SceneAnnotation try_new rejected: {0}")]
SceneAnnotation(#[from] SceneAnnotationError),
#[cfg(feature = "audio")]
#[error("Audio try_new rejected: {0}")]
Audio(#[from] AudioError),
#[cfg(feature = "audio")]
#[error("AudioTrack try_new rejected: {0}")]
AudioTrack(#[from] AudioTrackError),
#[cfg(feature = "audio")]
#[error("AudioSegment try_new rejected: {0}")]
AudioSegment(#[from] AudioSegmentError),
#[cfg(feature = "audio")]
#[error("Word try_from_parts rejected: {0}")]
Word(#[from] WordError),
#[cfg(feature = "video")]
#[error("Video try_new rejected: {0}")]
Video(#[from] VideoError),
#[cfg(feature = "video")]
#[error("VideoTrack try_new rejected: {0}")]
VideoTrack(#[from] VideoTrackError),
#[cfg(feature = "video")]
#[error("Scene try_new rejected: {0}")]
Scene(#[from] SceneError),
#[cfg(feature = "video")]
#[error("Keyframe try_new rejected: {0}")]
Keyframe(#[from] KeyframeError),
#[cfg(feature = "video")]
#[error("keyframe detection VO try_new rejected: {0}")]
Detection(#[from] DetectionError),
#[cfg(feature = "subtitle")]
#[error("Subtitle try_new rejected: {0}")]
Subtitle(#[from] SubtitleError),
#[cfg(feature = "subtitle")]
#[error("SubtitleTrack try_new rejected: {0}")]
SubtitleTrack(#[from] SubtitleTrackError),
#[cfg(feature = "subtitle")]
#[error("SubtitleCue try_new rejected: {0}")]
SubtitleCue(#[from] SubtitleCueError),
}
impl MongoError {
#[inline]
pub fn missing(field: impl Into<SmolStr>) -> Self {
Self::MissingField(field.into())
}
#[inline]
pub fn type_mismatch(field: impl Into<SmolStr>, want: &'static str, got: &'static str) -> Self {
Self::TypeMismatch {
field: field.into(),
want,
got,
}
}
}