Skip to main content

aocl_error/
lib.rs

1//! Cross-component error type shared by every `aocl-*` safe wrapper.
2
3use thiserror::Error;
4
5/// Crate result alias — used by every `aocl-*` safe wrapper crate.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Errors that can be returned by safe AOCL wrappers.
9///
10/// Each AOCL component has its own native error code conventions; this
11/// enum is the lowest common denominator. Component-specific modules layer
12/// their own typed errors on top where useful.
13#[derive(Debug, Error)]
14#[non_exhaustive]
15pub enum Error {
16    /// An AOCL routine returned a non-success status code.
17    #[error("AOCL '{component}' returned error code {code}: {message}")]
18    Status {
19        /// AOCL component that produced the error (e.g. `"blas"`, `"lapack"`).
20        component: &'static str,
21        /// Native return code from the AOCL routine.
22        code: i64,
23        /// Human-readable interpretation when one is available.
24        message: String,
25    },
26
27    /// Invalid arguments passed by the caller (dimension mismatch, null
28    /// buffer, etc.). These are detected client-side before invoking AOCL.
29    #[error("invalid argument: {0}")]
30    InvalidArgument(String),
31
32    /// A memory allocation requested by AOCL failed.
33    #[error("AOCL allocation failed in component '{0}'")]
34    AllocationFailed(&'static str),
35
36    /// A C string returned by AOCL was not valid UTF-8.
37    #[error("AOCL returned a non-UTF-8 string: {0}")]
38    InvalidUtf8(#[from] std::str::Utf8Error),
39
40    /// A C string returned by AOCL was missing its NUL terminator within
41    /// the inspected window.
42    #[error("AOCL returned a string without NUL terminator")]
43    MissingNul,
44}