pict-rs/src/exiftool.rs

36 lines
987 B
Rust
Raw Normal View History

2024-02-24 19:21:35 +00:00
use crate::{error_code::ErrorCode, process::ProcessError};
2022-10-15 16:13:24 +00:00
2023-07-10 20:29:41 +00:00
#[derive(Debug, thiserror::Error)]
pub(crate) enum ExifError {
#[error("Error in process")]
Process(#[source] ProcessError),
#[error("Invalid media file provided")]
CommandFailed(ProcessError),
}
impl From<ProcessError> for ExifError {
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 ExifError {
2023-09-02 01:50:10 +00:00
pub(crate) const fn error_code(&self) -> ErrorCode {
match self {
Self::Process(e) => e.error_code(),
Self::CommandFailed(_) => ErrorCode::COMMAND_FAILURE,
}
}
2023-07-10 20:29:41 +00:00
pub(crate) fn is_client_error(&self) -> bool {
// if exiftool bails we probably have bad input
2023-12-23 03:00:37 +00:00
match self {
Self::CommandFailed(_) => true,
Self::Process(e) => e.is_client_error(),
}
2023-07-10 20:29:41 +00:00
}
}