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.
ConnectionLost
WebSocket connection was lost after being established.
NotConnected
The client is not connected to the Cortex service.
AuthenticationFailed
Authentication failed (invalid client_id/client_secret or expired token).
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.
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.
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.
SessionError
Session-related error (create, update, close failed).
StreamError
Subscribe/unsubscribe failed for the requested streams.
ApiError
Raw Cortex API error that doesn’t map to a more specific variant.
CortexStarting
The Cortex service is still starting up — try again shortly.
MethodNotFound
The requested API method was not found (likely a version mismatch).
Timeout
An operation timed out waiting for a response.
RetriesExhausted
All retry attempts have been exhausted.
ProtocolError
Received an unexpected or malformed message from the Cortex service.
ConfigError
Configuration file error (missing, malformed, or invalid values).
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
impl CortexError
Sourcepub fn from_api_error(code: i32, message: impl Into<String>) -> Self
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));Sourcepub fn is_retryable(&self) -> bool
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());Sourcepub fn is_connection_error(&self) -> bool
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());