visual_cortex_capture/
error.rs1#[derive(Debug, thiserror::Error)]
2pub enum CaptureError {
3 #[error(
4 "invalid frame data: expected {expected} bytes for {width}x{height} BGRA, got {actual}"
5 )]
6 InvalidFrameData {
7 width: u32,
8 height: u32,
9 expected: usize,
10 actual: usize,
11 },
12
13 #[error("invalid region: {0}")]
14 InvalidRegion(String),
15
16 #[error("capture backend error: {0}")]
17 Backend(String),
18
19 #[error("capture target not found: {0}")]
20 TargetNotFound(String),
21
22 #[error("capture target lost")]
23 TargetLost,
24
25 #[error("screen capture permission denied: {0}")]
26 PermissionDenied(String),
27
28 #[error("frame source is exhausted")]
29 Exhausted,
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 #[test]
37 fn new_error_variants_format() {
38 assert_eq!(CaptureError::TargetLost.to_string(), "capture target lost");
39 assert!(CaptureError::TargetNotFound("display index 3".into())
40 .to_string()
41 .contains("display index 3"));
42 assert!(
43 CaptureError::PermissionDenied("grant Screen Recording".into())
44 .to_string()
45 .contains("grant Screen Recording")
46 );
47 }
48}