Skip to main content

edgefirst_tensor/
error.rs

1// SPDX-FileCopyrightText: Copyright 2025 Au-Zone Technologies
2// SPDX-License-Identifier: Apache-2.0
3
4pub type Result<T, E = Error> = std::result::Result<T, E>;
5
6#[derive(Debug)]
7pub enum Error {
8    IoError(std::io::Error),
9    #[cfg(unix)]
10    NixError(nix::Error),
11    NotImplemented(String),
12    InvalidSize(usize),
13    ShapeMismatch(String),
14    #[cfg(target_os = "linux")]
15    UnknownDeviceType(u64, u64),
16    InvalidMemoryType(String),
17    /// The GL context backing a PBO tensor has been destroyed.
18    PboDisconnected,
19    /// The PBO buffer is currently mapped and cannot be used for GL operations.
20    PboMapped,
21    #[cfg(feature = "ndarray")]
22    NdArrayError(ndarray::ShapeError),
23    InvalidShape(String),
24    InvalidArgument(String),
25    InvalidOperation(String),
26}
27
28impl From<std::io::Error> for Error {
29    fn from(err: std::io::Error) -> Self {
30        Error::IoError(err)
31    }
32}
33#[cfg(unix)]
34impl From<nix::Error> for Error {
35    fn from(err: nix::Error) -> Self {
36        Error::NixError(err)
37    }
38}
39
40#[cfg(feature = "ndarray")]
41impl From<ndarray::ShapeError> for Error {
42    fn from(err: ndarray::ShapeError) -> Self {
43        Error::NdArrayError(err)
44    }
45}
46
47impl std::fmt::Display for Error {
48    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49        write!(f, "{self:?}")
50    }
51}
52
53impl std::error::Error for Error {}