snarkvm_utilities/serialize/error.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
16#[derive(Error, Debug)]
17pub enum SerializationError {
18 #[error("{}", _0)]
19 AnyhowError(#[from] anyhow::Error),
20 /// During serialization with bincode, we encountered a serialization issue
21 #[error(transparent)]
22 BincodeError(#[from] bincode::Error),
23 /// During serialization we could not serialize to the right sized int
24 #[error(transparent)]
25 IntError(#[from] std::num::TryFromIntError),
26 /// During serialization, the data was invalid.
27 #[error("the input buffer contained invalid data")]
28 InvalidData,
29 /// During serialization, we countered an I/O error.
30 #[error("IoError: {0}")]
31 IoError(#[from] crate::io::Error),
32 /// During serialization, we didn't have enough space to write extra info.
33 #[error("the last byte does not have enough space to encode the extra info bits")]
34 NotEnoughSpace,
35 /// During serialization, non-empty flags were given where none were
36 /// expected.
37 #[error("the call expects empty flags")]
38 UnexpectedFlags,
39 /// During serialization, the target was found to be incompatible
40 #[error("the value was serialized on a target that is incompatible with the current target")]
41 IncompatibleTarget,
42}
43
44impl From<SerializationError> for crate::io::Error {
45 fn from(error: SerializationError) -> Self {
46 crate::io::Error::new(crate::io::ErrorKind::Other, format!("{error}"))
47 }
48}