snarkvm_parameters/errors/
parameter.rs

1// Copyright 2024 Aleo Network Foundation
2// This file is part of the snarkVM library.
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
16use std::fmt::Debug;
17
18#[derive(Debug, Error)]
19pub enum ParameterError {
20    #[error("expected checksum of {}, found checksum of {}", _0, _1)]
21    ChecksumMismatch(String, String),
22
23    #[error("{}: {}", _0, _1)]
24    Crate(&'static str, String),
25
26    #[error("{}", _0)]
27    Message(String),
28
29    #[error("Remote fetch is disabled, enable compiler flag for feature")]
30    RemoteFetchDisabled,
31
32    #[error("Expected size of {}, found size of {}", _0, _1)]
33    SizeMismatch(usize, usize),
34
35    #[error("{}", _0)]
36    Wasm(String),
37}
38
39#[cfg(not(feature = "wasm"))]
40impl From<curl::Error> for ParameterError {
41    fn from(error: curl::Error) -> Self {
42        ParameterError::Crate("curl::error", format!("{error:?}"))
43    }
44}
45
46impl From<std::io::Error> for ParameterError {
47    fn from(error: std::io::Error) -> Self {
48        ParameterError::Crate("std::io", format!("{error:?}"))
49    }
50}
51
52impl From<std::path::StripPrefixError> for ParameterError {
53    fn from(error: std::path::StripPrefixError) -> Self {
54        ParameterError::Crate("std::path", format!("{error:?}"))
55    }
56}
57
58impl From<ParameterError> for std::io::Error {
59    fn from(error: ParameterError) -> Self {
60        std::io::Error::new(std::io::ErrorKind::Other, format!("{error:?}"))
61    }
62}