Skip to main content

CortexError

Enum CortexError 

Source
pub enum CortexError {
Show 25 variants ConnectionFailed { url: String, reason: String, }, ConnectionLost { reason: String, }, NotConnected, AuthenticationFailed { reason: String, }, TokenExpired, AccessDenied { reason: String, }, UserNotLoggedIn, NotApproved, LicenseError { reason: String, }, NoHeadsetFound, HeadsetInUse, HeadsetError { reason: String, }, SessionError { reason: String, }, StreamError { reason: String, }, ApiError { code: i32, message: String, }, CortexStarting, MethodNotFound { method: String, }, Timeout { seconds: u64, }, RetriesExhausted { attempts: u32, last_error: Box<CortexError>, }, ProtocolError { reason: String, }, ConfigError { reason: String, }, WebSocket(String), Tls(String), Io(Error), Json(Error),
}
Expand description

All errors that can occur when interacting with the Emotiv Cortex API.

Variants§

§

ConnectionFailed

Failed to establish a WebSocket connection to the Cortex service.

Fields

§reason: String
§

ConnectionLost

WebSocket connection was lost after being established.

Fields

§reason: String
§

NotConnected

The client is not connected to the Cortex service.

§

AuthenticationFailed

Authentication failed (invalid client_id/client_secret or expired token).

Fields

§reason: String
§

TokenExpired

The Cortex token has expired and needs to be refreshed.

§

AccessDenied

Access denied — the user hasn’t approved the app in the Emotiv Launcher.

Fields

§reason: String
§

UserNotLoggedIn

User is not logged in to EmotivID in the Launcher.

§

NotApproved

The application has not been approved in the EMOTIV Launcher.

§

LicenseError

License expired, invalid, or missing for the requested operation.

Fields

§reason: String
§

NoHeadsetFound

No headset found (either not paired or not powered on).

§

HeadsetInUse

The headset is being used by another session or application.

§

HeadsetError

Headset connection failed or the headset disconnected unexpectedly.

Fields

§reason: String
§

SessionError

Session-related error (create, update, close failed).

Fields

§reason: String
§

StreamError

Subscribe/unsubscribe failed for the requested streams.

Fields

§reason: String
§

ApiError

Raw Cortex API error that doesn’t map to a more specific variant.

Fields

§code: i32
§message: String
§

CortexStarting

The Cortex service is still starting up — try again shortly.

§

MethodNotFound

The requested API method was not found (likely a version mismatch).

Fields

§method: String
§

Timeout

An operation timed out waiting for a response.

Fields

§seconds: u64
§

RetriesExhausted

All retry attempts have been exhausted.

Fields

§attempts: u32
§last_error: Box<CortexError>
§

ProtocolError

Received an unexpected or malformed message from the Cortex service.

Fields

§reason: String
§

ConfigError

Configuration file error (missing, malformed, or invalid values).

Fields

§reason: String
§

WebSocket(String)

Low-level WebSocket transport error.

§

Tls(String)

TLS/SSL error during connection.

§

Io(Error)

Filesystem or I/O error (config file reading, etc.).

§

Json(Error)

JSON serialization/deserialization error.

Implementations§

Source§

impl CortexError

Source

pub fn from_api_error(code: i32, message: impl Into<String>) -> Self

Map a Cortex API error code + message to the most specific error variant.

Known error codes from the Cortex v2 API docs (2026-02-12):

  • -32601: Method not found
  • -32001: No headset connected
  • -32002: Invalid license ID
  • -32004: Headset unavailable
  • -32005: Session already exists
  • -32012: Session must be activated
  • -32014: Invalid cortex token
  • -32015: Cortex token expired
  • -32016: Invalid stream
  • -32021: Invalid client credentials
  • -32024: License expired
  • -32033: User not logged in
  • -32142: Unpublished/unapproved application
  • -32152: Headset not ready

Legacy Cortex deployments may also return older codes such as -32102 and -32122.

§Examples
use emotiv_cortex_v2::CortexError;

let err = CortexError::from_api_error(-32015, "token expired");
assert!(matches!(err, CortexError::TokenExpired));

let err = CortexError::from_api_error(-32001, "no headset");
assert!(matches!(err, CortexError::NoHeadsetFound));
Source

pub fn is_retryable(&self) -> bool

Returns true if this error is transient and the operation can be retried.

§Examples
use emotiv_cortex_v2::CortexError;

assert!(CortexError::Timeout { seconds: 10 }.is_retryable());
assert!(CortexError::CortexStarting.is_retryable());
assert!(!CortexError::NoHeadsetFound.is_retryable());
Source

pub fn is_connection_error(&self) -> bool

Returns true if this error indicates the connection is dead and a reconnect is needed.

§Examples
use emotiv_cortex_v2::CortexError;

assert!(CortexError::NotConnected.is_connection_error());
assert!(!CortexError::TokenExpired.is_connection_error());

Trait Implementations§

Source§

impl Debug for CortexError

Source§

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

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

impl Display for CortexError

Source§

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

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

impl Error for CortexError

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<Error> for CortexError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for CortexError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for CortexError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for CortexError

Available on crate feature config-toml only.
Source§

fn from(err: Error) -> Self

Converts to this type from the input type.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more