#[non_exhaustive]pub enum SCError {
Show 22 variants
InvalidConfiguration(String),
InvalidDimension {
field: String,
value: usize,
},
InvalidPixelFormat(String),
NoShareableContent(String),
DisplayNotFound(String),
WindowNotFound(String),
ApplicationNotFound(String),
StreamError(String),
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,
},
SCStreamError {
code: SCStreamErrorCode,
message: Option<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 (Non-exhaustive)§
This enum is marked as non-exhaustive
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 (generic)
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 (for non-SCStream errors)
SCStreamError
ScreenCaptureKit stream error with specific error code
This variant wraps Apple’s SCStreamError.Code for precise error handling.
Use SCStreamErrorCode to match specific error conditions.
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"));Sourcepub fn from_stream_error_code(code: SCStreamErrorCode) -> Self
pub fn from_stream_error_code(code: SCStreamErrorCode) -> Self
Create an error from an SCStreamErrorCode
§Examples
use screencapturekit::error::{SCError, SCStreamErrorCode};
let err = SCError::from_stream_error_code(SCStreamErrorCode::UserDeclined);
assert!(err.to_string().contains("User declined"));Sourcepub fn from_stream_error_code_with_message(
code: SCStreamErrorCode,
message: impl Into<String>,
) -> Self
pub fn from_stream_error_code_with_message( code: SCStreamErrorCode, message: impl Into<String>, ) -> Self
Create an error from an SCStreamErrorCode with additional message
§Examples
use screencapturekit::error::{SCError, SCStreamErrorCode};
let err = SCError::from_stream_error_code_with_message(
SCStreamErrorCode::FailedToStart,
"No available displays"
);
assert!(err.to_string().contains("Failed to start"));Sourcepub fn from_error_code(code: i32) -> Self
pub fn from_error_code(code: i32) -> Self
Create an error from a raw error code
If the code matches a known SCStreamErrorCode, creates an SCStreamError.
Otherwise, creates an OSError.
§Examples
use screencapturekit::error::SCError;
// Known SCStreamError code
let err = SCError::from_error_code(-3801); // UserDeclined
assert!(matches!(err, SCError::SCStreamError { .. }));
// Unknown code falls back to OSError
let err = SCError::from_error_code(-999);
assert!(matches!(err, SCError::OSError { .. }));Sourcepub fn stream_error_code(&self) -> Option<SCStreamErrorCode>
pub fn stream_error_code(&self) -> Option<SCStreamErrorCode>
Get the SCStreamErrorCode if this is an SCStreamError
§Examples
use screencapturekit::error::{SCError, SCStreamErrorCode};
let err = SCError::from_stream_error_code(SCStreamErrorCode::UserDeclined);
assert_eq!(err.stream_error_code(), Some(SCStreamErrorCode::UserDeclined));
let err = SCError::StreamError("test".to_string());
assert_eq!(err.stream_error_code(), None);