randomx_rust_wrapper/
errors.rs

1/*
2 * Copyright 2024 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use thiserror::Error as ThisError;
18
19use crate::flags::RandomXFlags;
20
21#[derive(ThisError, Debug, Clone)]
22pub enum RandomXError {
23    #[error("cache allocation with flags {flags:?} failed")]
24    CacheAllocationFailed { flags: RandomXFlags },
25
26    #[error("dataset allocation with flags {flags:?} failed")]
27    DatasetAllocationError { flags: RandomXFlags },
28
29    #[error(transparent)]
30    VMCreationFailed(#[from] VmCreationError),
31}
32
33#[derive(ThisError, Debug, Clone)]
34pub enum VmCreationError {
35    #[error("vm allocation with flags {flags:?} failed")]
36    AllocationFailed { flags: RandomXFlags },
37
38    #[error("to allocate vm in the fast mode, flags {flags:?} must contain the full mem option")]
39    IncorrectFastModeFlag { flags: RandomXFlags },
40
41    #[error(
42        "to allocate vm in the light mode, flags {flags:?} must no contain the full mem option"
43    )]
44    IncorrectLightModeFlag { flags: RandomXFlags },
45}