winter_utils/errors.rs
1// Copyright (c) Facebook, Inc. and its affiliates.
2//
3// This source code is licensed under the MIT license found in the
4// LICENSE file in the root directory of this source tree.
5
6use alloc::string::String;
7use core::fmt;
8
9// DESERIALIZATION ERROR
10// ================================================================================================
11
12/// Defines errors which can occur during deserialization.
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub enum DeserializationError {
15 /// Bytes in the input do not represent a valid value.
16 InvalidValue(String),
17 /// An end of input was reached before a valid value could be deserialized.
18 UnexpectedEOF,
19 /// Deserialization has finished but not all bytes have been consumed.
20 UnconsumedBytes,
21 /// An unknown error has occurred.
22 UnknownError(String),
23}
24
25impl fmt::Display for DeserializationError {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 Self::InvalidValue(err_msg) => write!(f, "{err_msg}"),
29 Self::UnexpectedEOF => write!(f, "unexpected EOF"),
30 Self::UnconsumedBytes => write!(f, "not all bytes were consumed"),
31 Self::UnknownError(err_msg) => write!(f, "unknown error: {err_msg}"),
32 }
33 }
34}
35
36impl core::error::Error for DeserializationError {}