Skip to main content

dusk_data_driver/
error.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4//
5// Copyright (c) DUSK NETWORK. All rights reserved.
6
7//! Error-type for dusk-core.
8
9use alloc::string::{String, ToString};
10use core::fmt;
11
12/// The dusk-core error type.
13#[derive(Debug, Clone, PartialEq)]
14pub enum Error {
15    /// Rkyv serialization.
16    Rkyv(String),
17    /// Json serialization
18    Json(String),
19    /// Unsupported
20    Unsupported(String),
21    /// Other
22    Other(String),
23    /// WASM runtime error (reader feature only)
24    #[cfg(feature = "reader")]
25    WasmRuntime(String),
26    /// WASM memory error (reader feature only)
27    #[cfg(feature = "reader")]
28    WasmMemory(String),
29    /// WASM export error (reader feature only)
30    #[cfg(feature = "reader")]
31    WasmExport(String),
32    /// FFI call error (reader feature only)
33    #[cfg(feature = "reader")]
34    FfiError(String),
35}
36
37impl fmt::Display for Error {
38    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39        write!(f, "Data-Driver Error: {:?}", &self)
40    }
41}
42
43impl From<serde_json::Error> for Error {
44    fn from(value: serde_json::Error) -> Self {
45        Self::Json(value.to_string())
46    }
47}