use ff_format::{ErrorSeverity, MediaError};
use std::path::PathBuf;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum PreviewImageError {
#[error("Cannot create output file: {path}")]
CannotCreateFile {
path: PathBuf,
},
#[error("Unsupported codec: {codec}")]
UnsupportedCodec {
codec: String,
},
#[error("preview operation failed: {reason}")]
OperationFailed {
reason: String,
},
#[error("ffmpeg error: {message} (code={code})")]
Ffmpeg {
code: i32,
message: String,
},
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
}
impl PreviewImageError {
pub(crate) fn from_ffmpeg_error(errnum: i32) -> Self {
PreviewImageError::Ffmpeg {
code: errnum,
message: ff_sys::av_error_string(errnum),
}
}
}
impl MediaError for PreviewImageError {
fn severity(&self) -> ErrorSeverity {
match self {
Self::Ffmpeg { .. } => ErrorSeverity::Other,
Self::CannotCreateFile { .. }
| Self::UnsupportedCodec { .. }
| Self::OperationFailed { .. }
| Self::Io(_) => ErrorSeverity::Fatal,
}
}
}