#[derive(Debug, thiserror::Error)]
pub enum CaptureError {
#[error(
"invalid frame data: expected {expected} bytes for {width}x{height} BGRA, got {actual}"
)]
InvalidFrameData {
width: u32,
height: u32,
expected: usize,
actual: usize,
},
#[error("invalid region: {0}")]
InvalidRegion(String),
#[error("capture backend error: {0}")]
Backend(String),
#[error("capture target not found: {0}")]
TargetNotFound(String),
#[error("capture target lost")]
TargetLost,
#[error("screen capture permission denied: {0}")]
PermissionDenied(String),
#[error("frame source is exhausted")]
Exhausted,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn new_error_variants_format() {
assert_eq!(CaptureError::TargetLost.to_string(), "capture target lost");
assert!(CaptureError::TargetNotFound("display index 3".into())
.to_string()
.contains("display index 3"));
assert!(
CaptureError::PermissionDenied("grant Screen Recording".into())
.to_string()
.contains("grant Screen Recording")
);
}
}