parameter.rs
1 // Copyright (c) 2019-2025 Alpha-Delta Network Inc. 2 // This file is part of the deltavm 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 16 use std::fmt::Debug; 17 18 #[derive(Debug, Error)] 19 pub 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 #[error("Filesystem access is disabled, enable compiler flag for feature")] 39 FilesystemDisabled, 40 } 41 42 #[cfg(all(not(feature = "wasm"), not(target_env = "sgx")))] 43 impl From<curl::Error> for ParameterError { 44 fn from(error: curl::Error) -> Self { 45 ParameterError::Crate("curl::error", format!("{error:?}")) 46 } 47 } 48 49 impl From<std::io::Error> for ParameterError { 50 fn from(error: std::io::Error) -> Self { 51 ParameterError::Crate("std::io", format!("{error:?}")) 52 } 53 } 54 55 impl From<std::path::StripPrefixError> for ParameterError { 56 fn from(error: std::path::StripPrefixError) -> Self { 57 ParameterError::Crate("std::path", format!("{error:?}")) 58 } 59 } 60 61 impl From<ParameterError> for std::io::Error { 62 fn from(error: ParameterError) -> Self { 63 std::io::Error::other(format!("{error:?}")) 64 } 65 }