mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-14 04:41:01 +00:00
fix: forward more errors in de::value::Error
When using a `ValueDeserializer` errors produced with the methods `type_mismatch`, `length_mismatch` and `syntax` were not forwarded correctly. These methods now store all information in the enum `de::value::Error`.
This commit is contained in:
@@ -33,6 +33,7 @@ pub trait Error: Sized {
|
|||||||
|
|
||||||
/// `Type` represents all the primitive types that can be deserialized. This is used by
|
/// `Type` represents all the primitive types that can be deserialized. This is used by
|
||||||
/// `Error::kind_mismatch`.
|
/// `Error::kind_mismatch`.
|
||||||
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
pub enum Type {
|
pub enum Type {
|
||||||
/// Represents a `bool` type.
|
/// Represents a `bool` type.
|
||||||
Bool,
|
Bool,
|
||||||
|
|||||||
+10
-2
@@ -22,7 +22,13 @@ use bytes;
|
|||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// The value had some syntatic error.
|
/// The value had some syntatic error.
|
||||||
SyntaxError,
|
SyntaxError(String),
|
||||||
|
|
||||||
|
/// The value had an incorrect type.
|
||||||
|
TypeError(de::Type),
|
||||||
|
|
||||||
|
/// The value had an invalid length.
|
||||||
|
LengthError(usize),
|
||||||
|
|
||||||
/// EOF while deserializing a value.
|
/// EOF while deserializing a value.
|
||||||
EndOfStreamError,
|
EndOfStreamError,
|
||||||
@@ -35,7 +41,9 @@ pub enum Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl de::Error for Error {
|
impl de::Error for Error {
|
||||||
fn syntax(_: &str) -> Self { Error::SyntaxError }
|
fn syntax(msg: &str) -> Self { Error::SyntaxError(String::from(msg)) }
|
||||||
|
fn type_mismatch(type_: de::Type) -> Self { Error::TypeError(type_) }
|
||||||
|
fn length_mismatch(len: usize) -> Self { Error::LengthError(len) }
|
||||||
fn end_of_stream() -> Self { Error::EndOfStreamError }
|
fn end_of_stream() -> Self { Error::EndOfStreamError }
|
||||||
fn unknown_field(field: &str) -> Self { Error::UnknownFieldError(String::from(field)) }
|
fn unknown_field(field: &str) -> Self { Error::UnknownFieldError(String::from(field)) }
|
||||||
fn missing_field(field: &'static str) -> Self { Error::MissingFieldError(field) }
|
fn missing_field(field: &'static str) -> Self { Error::MissingFieldError(field) }
|
||||||
|
|||||||
Reference in New Issue
Block a user