Skip to main content

maa_framework/
error.rs

1//! Error types and result aliases for the MAA framework.
2
3use std::ffi::NulError;
4use std::str::Utf8Error;
5use thiserror::Error;
6
7#[derive(Error, Debug)]
8#[non_exhaustive]
9pub enum MaaError {
10    #[error("Null pointer exception")]
11    NullPointer,
12
13    #[error("Invalid arguments: {0}")]
14    InvalidArgument(String),
15
16    #[error("Invalid value: {0}")]
17    InvalidValue(i64),
18
19    #[error("MaaFramework internal error: status {0}")]
20    FrameworkError(i32),
21
22    #[error("String conversion error: {0}")]
23    Utf8Error(#[from] Utf8Error),
24
25    #[error("CString creation error: {0}")]
26    NulError(#[from] NulError),
27
28    #[error("Timeout")]
29    Timeout,
30
31    #[error("Device connection failed")]
32    DeviceConnectionFailed,
33
34    #[error("Invalid configuration: {0}")]
35    InvalidConfig(String),
36
37    #[error("Resource not loaded")]
38    ResourceNotLoaded,
39
40    #[error("Context not initialized")]
41    ContextNotInitialized,
42
43    #[error("Task failed")]
44    TaskFailed,
45
46    #[error("JSON error: {0}")]
47    JsonError(#[from] serde_json::Error),
48
49    #[error("Image conversion error")]
50    ImageConversionError,
51}
52
53pub type MaaResult<T> = Result<T, MaaError>;
54
55impl From<i32> for MaaError {
56    fn from(status: i32) -> Self {
57        MaaError::FrameworkError(status)
58    }
59}