SCError

Enum SCError 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

InvalidConfiguration(String)

Invalid configuration parameter

§

InvalidDimension

Invalid dimension value (width or height)

Fields

§field: String
§value: usize
§

InvalidPixelFormat(String)

Invalid pixel format

§

NoShareableContent(String)

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

Fields

§feature: String
§required_version: String
§

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)

Fields

§code: i32
§message: String
§

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.

Fields

§message: Option<String>

Implementations§

Source§

impl SCError

Source

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"));
Source

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"));
Source

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"));
Source

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"));
Source

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"));
Source

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"));
Source

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"));
Source

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"));
Source

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"));
Source

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

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"));
Source

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"));
Source

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 { .. }));
Source

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);

Trait Implementations§

Source§

impl Clone for SCError

Source§

fn clone(&self) -> SCError

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SCError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for SCError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for SCError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<SCStreamErrorCode> for SCError

Source§

fn from(code: SCStreamErrorCode) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for SCError

Source§

fn eq(&self, other: &SCError) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for SCError

Source§

impl StructuralPartialEq for SCError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.