2023-09-24 16:54:16 +00:00
|
|
|
use crate::{error_code::ErrorCode, process::ProcessError, store::StoreError};
|
2023-07-10 20:29:41 +00:00
|
|
|
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
|
|
pub(crate) enum FfMpegError {
|
|
|
|
#[error("Error in ffmpeg process")]
|
|
|
|
Process(#[source] ProcessError),
|
|
|
|
|
|
|
|
#[error("Error writing bytes")]
|
|
|
|
Write(#[source] std::io::Error),
|
|
|
|
|
|
|
|
#[error("Invalid output format")]
|
|
|
|
Json(#[source] serde_json::Error),
|
|
|
|
|
|
|
|
#[error("Error creating parent directory")]
|
|
|
|
CreateDir(#[source] crate::store::file_store::FileError),
|
|
|
|
|
|
|
|
#[error("Error reading file to stream")]
|
|
|
|
ReadFile(#[source] crate::store::file_store::FileError),
|
|
|
|
|
|
|
|
#[error("Error opening file")]
|
|
|
|
OpenFile(#[source] std::io::Error),
|
|
|
|
|
|
|
|
#[error("Error creating file")]
|
|
|
|
CreateFile(#[source] std::io::Error),
|
|
|
|
|
|
|
|
#[error("Error closing file")]
|
|
|
|
CloseFile(#[source] std::io::Error),
|
|
|
|
|
|
|
|
#[error("Error in store")]
|
|
|
|
Store(#[source] StoreError),
|
|
|
|
|
2023-07-17 18:30:08 +00:00
|
|
|
#[error("Invalid media file provided")]
|
|
|
|
CommandFailed(ProcessError),
|
2023-07-10 20:29:41 +00:00
|
|
|
}
|
|
|
|
|
2023-07-17 18:30:08 +00:00
|
|
|
impl From<ProcessError> for FfMpegError {
|
|
|
|
fn from(value: ProcessError) -> Self {
|
|
|
|
match value {
|
|
|
|
e @ ProcessError::Status(_, _) => Self::CommandFailed(e),
|
|
|
|
otherwise => Self::Process(otherwise),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-10 20:29:41 +00:00
|
|
|
impl FfMpegError {
|
2023-09-02 01:50:10 +00:00
|
|
|
pub(crate) const fn error_code(&self) -> ErrorCode {
|
|
|
|
match self {
|
|
|
|
Self::CommandFailed(_) => ErrorCode::COMMAND_FAILURE,
|
|
|
|
Self::Store(s) => s.error_code(),
|
|
|
|
Self::Process(e) => e.error_code(),
|
2023-12-23 03:00:37 +00:00
|
|
|
Self::Write(_)
|
2023-09-02 01:50:10 +00:00
|
|
|
| Self::Json(_)
|
|
|
|
| Self::CreateDir(_)
|
|
|
|
| Self::ReadFile(_)
|
|
|
|
| Self::OpenFile(_)
|
|
|
|
| Self::CreateFile(_)
|
2023-11-10 00:20:59 +00:00
|
|
|
| Self::CloseFile(_) => ErrorCode::COMMAND_ERROR,
|
2023-09-02 01:50:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-10 20:29:41 +00:00
|
|
|
pub(crate) fn is_client_error(&self) -> bool {
|
|
|
|
// Failing validation or ffmpeg bailing probably means bad input
|
2023-08-05 21:18:06 +00:00
|
|
|
matches!(
|
|
|
|
self,
|
|
|
|
Self::CommandFailed(_) | Self::Process(ProcessError::Timeout(_))
|
|
|
|
)
|
2023-07-10 20:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn is_not_found(&self) -> bool {
|
|
|
|
if let Self::Store(e) = self {
|
|
|
|
return e.is_not_found();
|
|
|
|
}
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|