exiftool_rs_wrapper/
error.rs1use std::io;
4use thiserror::Error;
5
6#[derive(Error, Debug)]
8pub enum Error {
9 #[error("IO error: {0}")]
11 Io(#[from] io::Error),
12
13 #[error("ExifTool process error: {message}")]
15 Process {
16 message: String,
17 exit_code: Option<i32>,
18 },
19
20 #[error("Parse error: {0}")]
22 Parse(String),
23
24 #[error("Tag not found: {0}")]
26 TagNotFound(String),
27
28 #[error("Invalid argument: {0}")]
30 InvalidArgument(String),
31
32 #[error("ExifTool not found in PATH. Please install ExifTool: https://exiftool.org/")]
34 ExifToolNotFound,
35
36 #[error("Internal mutex poisoned")]
38 MutexPoisoned,
39
40 #[error("Serialization error: {0}")]
42 Serialization(#[from] serde_json::Error),
43
44 #[error("Operation timed out")]
46 Timeout,
47}
48
49pub type Result<T> = std::result::Result<T, Error>;
51
52impl Error {
53 pub fn process(message: impl Into<String>) -> Self {
55 Self::Process {
56 message: message.into(),
57 exit_code: None,
58 }
59 }
60
61 pub fn process_with_code(message: impl Into<String>, code: i32) -> Self {
63 Self::Process {
64 message: message.into(),
65 exit_code: Some(code),
66 }
67 }
68
69 pub fn parse(message: impl Into<String>) -> Self {
71 Self::Parse(message.into())
72 }
73
74 pub fn invalid_arg(message: impl Into<String>) -> Self {
76 Self::InvalidArgument(message.into())
77 }
78}
79
80impl From<std::sync::PoisonError<std::sync::MutexGuard<'_, crate::process::ExifToolInner>>>
81 for Error
82{
83 fn from(
84 _: std::sync::PoisonError<std::sync::MutexGuard<'_, crate::process::ExifToolInner>>,
85 ) -> Self {
86 Error::MutexPoisoned
87 }
88}
89
90#[cfg(test)]
91mod tests {
92 use super::*;
93
94 #[test]
95 fn test_error_creation() {
96 let err = Error::process("test error");
97 assert!(matches!(err, Error::Process { .. }));
98 assert!(err.to_string().contains("test error"));
99 }
100
101 #[test]
102 fn test_error_from_io() {
103 let io_err = io::Error::new(io::ErrorKind::NotFound, "file not found");
104 let err: Error = io_err.into();
105 assert!(matches!(err, Error::Io(_)));
106 }
107}