1use std::path::PathBuf;
4use thiserror::Error;
5
6#[derive(Error, Debug)]
8pub enum ProbeError {
9 #[error("File not found: {path}")]
11 FileNotFound {
12 path: PathBuf,
14 },
15
16 #[error("Cannot open file: {path} - {reason}")]
18 CannotOpen {
19 path: PathBuf,
21 reason: String,
23 },
24
25 #[error("Invalid media file: {path} - {reason}")]
27 InvalidMedia {
28 path: PathBuf,
30 reason: String,
32 },
33
34 #[error("No streams found in file: {path}")]
36 NoStreams {
37 path: PathBuf,
39 },
40
41 #[error("IO error: {0}")]
43 Io(#[from] std::io::Error),
44
45 #[error("FFmpeg error: {0}")]
47 Ffmpeg(String),
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_file_not_found_error() {
56 let err = ProbeError::FileNotFound {
57 path: PathBuf::from("/path/to/missing.mp4"),
58 };
59 let msg = err.to_string();
60 assert!(msg.contains("File not found"));
61 assert!(msg.contains("missing.mp4"));
62 }
63
64 #[test]
65 fn test_cannot_open_error() {
66 let err = ProbeError::CannotOpen {
67 path: PathBuf::from("/path/to/file.mp4"),
68 reason: "permission denied".to_string(),
69 };
70 let msg = err.to_string();
71 assert!(msg.contains("Cannot open file"));
72 assert!(msg.contains("permission denied"));
73 }
74
75 #[test]
76 fn test_invalid_media_error() {
77 let err = ProbeError::InvalidMedia {
78 path: PathBuf::from("/path/to/bad.mp4"),
79 reason: "corrupted header".to_string(),
80 };
81 let msg = err.to_string();
82 assert!(msg.contains("Invalid media file"));
83 assert!(msg.contains("corrupted header"));
84 }
85
86 #[test]
87 fn test_no_streams_error() {
88 let err = ProbeError::NoStreams {
89 path: PathBuf::from("/path/to/empty.mp4"),
90 };
91 let msg = err.to_string();
92 assert!(msg.contains("No streams found"));
93 }
94
95 #[test]
96 fn test_ffmpeg_error() {
97 let err = ProbeError::Ffmpeg("codec not found".to_string());
98 let msg = err.to_string();
99 assert!(msg.contains("FFmpeg error"));
100 assert!(msg.contains("codec not found"));
101 }
102
103 #[test]
104 fn test_io_error_conversion() {
105 let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
106 let err: ProbeError = io_err.into();
107 assert!(matches!(err, ProbeError::Io(_)));
108 }
109}