matroskin 0.1.0

whatsminer api client lib
Documentation
//! Error types for the `matroskin` crate.
//!
//! This module defines all errors that can occur when interacting with the
//! WhatsMiner API. The central type is [`enum@Error`], which is an enum of
//! error kinds that can be produced at various stages:
//!
//! - **I/O errors** – network or socket-level failures ([`Error::Io`]).
//! - **JSON errors** – failures to serialize or deserialize API messages ([`Error::Json`]).
//! - **Lifecycle and mailbox errors** – bounded lifecycle queue capacity exceeded
//!   ([`Error::LifecycleQueueFull`]), operations sent to a terminated actor
//!   ([`Error::ActorClosed`]).
//! - **Authentication errors** – a missing salt value ([`Error::SaltNotFound`]),
//!   missing permissions ([`Error::PermissionsNotFound`]), a corrupted token that
//!   could not be generated ([`Error::CorruptedToken`]), or a secured command
//!   invoked without the required auth data ([`Error::CommandShouldHaveAuthData`]).
//! - **Permission errors** – the current account lacks permission to execute
//!   a command ([`Error::NoPermission`]).
//! - **Encryption errors** – failures during AES-256-ECB parameter encryption
//!   ([`Error::EncryptionFailed`]).
//! - **Protocol and transport errors** – payloads not representable by the wire length
//!   ([`Error::ResponseTooLarge`]), I/O step timeouts ([`Error::Timeout`]),
//!   unexpected connection closures ([`Error::ConnectionClosed`]), connection loss
//!   ([`Error::ConnectionLost`]), or invalid UTF-8 payload ([`Error::InvalidUtf8`]).
//! - **Device errors** – protocol-level error response returned by the miner ([`Error::Device`]).
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
    #[error("Io error: {0}")]
    Io(#[from] std::io::Error),
    #[error("Json error: {0}")]
    Json(#[from] serde_json::Error),
    #[error("system clock is before the Unix epoch: {0}")]
    SystemTime(#[from] std::time::SystemTimeError),
    #[error("actor lifecycle queue is full")]
    LifecycleQueueFull,
    #[error("actor is closed")]
    ActorClosed,
    #[error("Salt not found")]
    SaltNotFound,
    #[error("Permissions not found")]
    PermissionsNotFound,
    #[error("Corrupted token")]
    CorruptedToken,
    #[error("Command {0}: should have AuthData ")]
    CommandShouldHaveAuthData(&'static str),
    #[error("Encryption failed")]
    EncryptionFailed,
    #[error("Response too large: {0} bytes")]
    ResponseTooLarge(usize),
    #[error("Command timed out")]
    Timeout,
    #[error("Connection closed")]
    ConnectionClosed,
    #[error("protocol error: {0}")]
    Protocol(String),
    #[error("Connection lost")]
    ConnectionLost,
    #[error("Invalid UTF-8 in command payload")]
    InvalidUtf8,
    #[error("no permission to execute `{command}` (requires {required}, but actor has {actual})")]
    NoPermission {
        command: &'static str,
        required: crate::permission::PermissionLevel,
        actual: crate::permission::PermissionLevel,
    },
    #[error("Device error: {code} - {msg} ({desc})")]
    Device {
        code: crate::response::ResponseCode,
        msg: String,
        desc: String,
    },
}

pub type Result<T> = std::result::Result<T, Error>;