pub enum SCError {
Show 23 variants
InvalidConfiguration(String),
InvalidDimension {
field: String,
value: usize,
},
InvalidPixelFormat(String),
NoShareableContent(String),
DisplayNotFound(String),
WindowNotFound(String),
ApplicationNotFound(String),
StreamError(String),
StreamAlreadyRunning,
StreamNotRunning,
CaptureStartFailed(String),
CaptureStopFailed(String),
BufferLockError(String),
BufferUnlockError(String),
InvalidBuffer(String),
ScreenshotError(String),
PermissionDenied(String),
FeatureNotAvailable {
feature: String,
required_version: String,
},
FFIError(String),
NullPointer(String),
Timeout(String),
InternalError(String),
OSError {
code: i32,
message: String,
},
}Expand description
Comprehensive error type for ScreenCaptureKit operations
This enum covers all possible error conditions that can occur when using
the ScreenCaptureKit API. Each variant provides specific context about
what went wrong.
§Examples
§Creating Errors
use screencapturekit::error::SCError;
// Using helper methods (recommended)
let err = SCError::invalid_dimension("width", 0);
assert_eq!(err.to_string(), "Invalid dimension: width must be greater than 0 (got 0)");
let err = SCError::permission_denied("Screen Recording");
assert!(err.to_string().contains("Screen Recording"));§Pattern Matching
use screencapturekit::error::SCError;
fn handle_error(err: SCError) {
match err {
SCError::InvalidDimension { field, value } => {
println!("Invalid {}: {}", field, value);
}
SCError::PermissionDenied(msg) => {
println!("Permission needed: {}", msg);
}
_ => println!("Other error: {}", err),
}
}Variants§
InvalidConfiguration(String)
Invalid configuration parameter
InvalidDimension
Invalid dimension value (width or height)
InvalidPixelFormat(String)
Invalid pixel format
No shareable content available
DisplayNotFound(String)
Display not found
WindowNotFound(String)
Window not found
ApplicationNotFound(String)
Application not found
StreamError(String)
Stream operation error
StreamAlreadyRunning
Stream already running
StreamNotRunning
Stream not running
CaptureStartFailed(String)
Failed to start capture
CaptureStopFailed(String)
Failed to stop capture
BufferLockError(String)
Buffer lock error
BufferUnlockError(String)
Buffer unlock error
InvalidBuffer(String)
Invalid buffer
ScreenshotError(String)
Screenshot capture error
PermissionDenied(String)
Permission denied
FeatureNotAvailable
Feature not available on this macOS version
FFIError(String)
FFI error
NullPointer(String)
Null pointer encountered
Timeout(String)
Timeout error
InternalError(String)
Generic internal error
OSError
OS error with code
Implementations§
Source§impl SCError
impl SCError
Sourcepub fn invalid_config(message: impl Into<String>) -> Self
pub fn invalid_config(message: impl Into<String>) -> Self
Create an invalid configuration error
§Examples
use screencapturekit::error::SCError;
let err = SCError::invalid_config("Queue depth must be positive");
assert!(err.to_string().contains("Queue depth"));Sourcepub fn invalid_dimension(field: impl Into<String>, value: usize) -> Self
pub fn invalid_dimension(field: impl Into<String>, value: usize) -> Self
Create an invalid dimension error
Use this when width or height validation fails.
§Examples
use screencapturekit::error::SCError;
let err = SCError::invalid_dimension("width", 0);
assert_eq!(
err.to_string(),
"Invalid dimension: width must be greater than 0 (got 0)"
);
let err = SCError::invalid_dimension("height", 0);
assert!(err.to_string().contains("height"));Sourcepub fn stream_error(message: impl Into<String>) -> Self
pub fn stream_error(message: impl Into<String>) -> Self
Create a stream error
§Examples
use screencapturekit::error::SCError;
let err = SCError::stream_error("Failed to start");
assert!(err.to_string().contains("Stream error"));Sourcepub fn permission_denied(message: impl Into<String>) -> Self
pub fn permission_denied(message: impl Into<String>) -> Self
Create a permission denied error
The error message automatically includes instructions to check System Preferences.
§Examples
use screencapturekit::error::SCError;
let err = SCError::permission_denied("Screen Recording");
let msg = err.to_string();
assert!(msg.contains("Screen Recording"));
assert!(msg.contains("System Preferences"));Sourcepub fn ffi_error(message: impl Into<String>) -> Self
pub fn ffi_error(message: impl Into<String>) -> Self
Create an FFI error
Use for errors crossing the Rust/Swift boundary.
§Examples
use screencapturekit::error::SCError;
let err = SCError::ffi_error("Swift bridge call failed");
assert!(err.to_string().contains("FFI error"));Sourcepub fn internal_error(message: impl Into<String>) -> Self
pub fn internal_error(message: impl Into<String>) -> Self
Create an internal error
§Examples
use screencapturekit::error::SCError;
let err = SCError::internal_error("Unexpected state");
assert!(err.to_string().contains("Internal error"));Sourcepub fn null_pointer(context: impl Into<String>) -> Self
pub fn null_pointer(context: impl Into<String>) -> Self
Create a null pointer error
§Examples
use screencapturekit::error::SCError;
let err = SCError::null_pointer("Display pointer");
assert!(err.to_string().contains("Null pointer"));
assert!(err.to_string().contains("Display pointer"));Sourcepub fn feature_not_available(
feature: impl Into<String>,
version: impl Into<String>,
) -> Self
pub fn feature_not_available( feature: impl Into<String>, version: impl Into<String>, ) -> Self
Create a feature not available error
Use when a feature requires a newer macOS version.
§Examples
use screencapturekit::error::SCError;
let err = SCError::feature_not_available("Screenshot Manager", "14.0");
let msg = err.to_string();
assert!(msg.contains("Screenshot Manager"));
assert!(msg.contains("14.0"));Sourcepub fn buffer_lock_error(message: impl Into<String>) -> Self
pub fn buffer_lock_error(message: impl Into<String>) -> Self
Create a buffer lock error
§Examples
use screencapturekit::error::SCError;
let err = SCError::buffer_lock_error("Already locked");
assert!(err.to_string().contains("lock pixel buffer"));Sourcepub fn os_error(code: i32, message: impl Into<String>) -> Self
pub fn os_error(code: i32, message: impl Into<String>) -> Self
Create an OS error with error code
§Examples
use screencapturekit::error::SCError;
let err = SCError::os_error(-1, "System call failed");
let msg = err.to_string();
assert!(msg.contains("-1"));
assert!(msg.contains("System call failed"));Source§impl SCError
impl SCError
Sourcepub fn new(message: impl Into<String>) -> Self
pub fn new(message: impl Into<String>) -> Self
Create from a message string (for backward compatibility)
Note: Prefer using specific error constructors like SCError::invalid_config
or other helper methods for better error categorization.
§Examples
use screencapturekit::error::SCError;
// Old style (still works)
let err = SCError::new("Something went wrong");
assert!(err.to_string().contains("Something went wrong"));Sourcepub fn message(&self) -> String
pub fn message(&self) -> String
Get the error message (for backward compatibility)
Note: Prefer using ToString::to_string which provides the same functionality.
§Examples
use screencapturekit::error::SCError;
let err = SCError::invalid_dimension("width", 0);
let msg = err.message();
assert!(msg.contains("width"));
assert!(msg.contains("0"));