Remove error serialization/deserialization (#3110)

it's not used
This commit is contained in:
hashmap 2019-11-13 21:08:20 +01:00 committed by GitHub
parent 8ce2bfda58
commit 76ac9419b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 469 deletions

View file

@ -23,7 +23,7 @@ use crate::util::{secp, secp_static, static_secp_instance};
use failure::Fail;
/// Errors from summing and verifying kernel excesses via committed trait.
#[derive(Debug, Clone, PartialEq, Eq, Fail, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Fail)]
pub enum Error {
/// Keychain related error.
#[fail(display = "Keychain error {}", _0)]

View file

@ -210,7 +210,7 @@ impl Readable for KernelFeatures {
}
/// Errors thrown by Transaction validation
#[derive(Clone, Eq, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Eq, Debug, PartialEq)]
pub enum Error {
/// Underlying Secp256k1 error (signature validation or invalid public key
/// typically)

View file

@ -26,7 +26,7 @@ pub struct Error {
inner: Context<ErrorKind>,
}
#[derive(Clone, Debug, Eq, Fail, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, Eq, Fail, PartialEq)]
/// Libwallet error types
pub enum ErrorKind {
/// SECP error

View file

@ -37,17 +37,10 @@ use std::marker;
use std::{cmp, error};
/// Possible errors deriving from serializing or deserializing.
#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, Eq, PartialEq, Debug)]
pub enum Error {
/// Wraps an io error produced when reading or writing
IOErr(
String,
#[serde(
serialize_with = "serialize_error_kind",
deserialize_with = "deserialize_error_kind"
)]
io::ErrorKind,
),
IOErr(String, io::ErrorKind),
/// Expected a given value that wasn't found
UnexpectedData {
/// What we wanted
@ -399,30 +392,26 @@ impl<'a> BinReader<'a> {
}
}
fn map_io_err(err: io::Error) -> Error {
Error::IOErr(format!("{}", err), err.kind())
}
/// Utility wrapper for an underlying byte Reader. Defines higher level methods
/// to read numbers, byte vectors, hashes, etc.
impl<'a> Reader for BinReader<'a> {
fn read_u8(&mut self) -> Result<u8, Error> {
self.source.read_u8().map_err(map_io_err)
self.source.read_u8().map_err(Into::into)
}
fn read_u16(&mut self) -> Result<u16, Error> {
self.source.read_u16::<BigEndian>().map_err(map_io_err)
self.source.read_u16::<BigEndian>().map_err(Into::into)
}
fn read_u32(&mut self) -> Result<u32, Error> {
self.source.read_u32::<BigEndian>().map_err(map_io_err)
self.source.read_u32::<BigEndian>().map_err(Into::into)
}
fn read_i32(&mut self) -> Result<i32, Error> {
self.source.read_i32::<BigEndian>().map_err(map_io_err)
self.source.read_i32::<BigEndian>().map_err(Into::into)
}
fn read_u64(&mut self) -> Result<u64, Error> {
self.source.read_u64::<BigEndian>().map_err(map_io_err)
self.source.read_u64::<BigEndian>().map_err(Into::into)
}
fn read_i64(&mut self) -> Result<i64, Error> {
self.source.read_i64::<BigEndian>().map_err(map_io_err)
self.source.read_i64::<BigEndian>().map_err(Into::into)
}
/// Read a variable size vector from the underlying Read. Expects a usize
fn read_bytes_len_prefix(&mut self) -> Result<Vec<u8>, Error> {
@ -440,7 +429,7 @@ impl<'a> Reader for BinReader<'a> {
self.source
.read_exact(&mut buf)
.map(move |_| buf)
.map_err(map_io_err)
.map_err(Into::into)
}
fn expect_u8(&mut self, val: u8) -> Result<u8, Error> {
@ -952,446 +941,3 @@ impl AsFixedBytes for crate::keychain::Identifier {
IDENTIFIER_SIZE
}
}
// serializer for io::Errorkind, originally auto-generated by serde-derive
// slightly modified to handle the #[non_exhaustive] tag on io::ErrorKind
fn serialize_error_kind<S>(
kind: &io::ErrorKind,
serializer: S,
) -> serde::export::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match *kind {
io::ErrorKind::NotFound => {
serde::Serializer::serialize_unit_variant(serializer, "ErrorKind", 0u32, "NotFound")
}
io::ErrorKind::PermissionDenied => serde::Serializer::serialize_unit_variant(
serializer,
"ErrorKind",
1u32,
"PermissionDenied",
),
io::ErrorKind::ConnectionRefused => serde::Serializer::serialize_unit_variant(
serializer,
"ErrorKind",
2u32,
"ConnectionRefused",
),
io::ErrorKind::ConnectionReset => serde::Serializer::serialize_unit_variant(
serializer,
"ErrorKind",
3u32,
"ConnectionReset",
),
io::ErrorKind::ConnectionAborted => serde::Serializer::serialize_unit_variant(
serializer,
"ErrorKind",
4u32,
"ConnectionAborted",
),
io::ErrorKind::NotConnected => {
serde::Serializer::serialize_unit_variant(serializer, "ErrorKind", 5u32, "NotConnected")
}
io::ErrorKind::AddrInUse => {
serde::Serializer::serialize_unit_variant(serializer, "ErrorKind", 6u32, "AddrInUse")
}
io::ErrorKind::AddrNotAvailable => serde::Serializer::serialize_unit_variant(
serializer,
"ErrorKind",
7u32,
"AddrNotAvailable",
),
io::ErrorKind::BrokenPipe => {
serde::Serializer::serialize_unit_variant(serializer, "ErrorKind", 8u32, "BrokenPipe")
}
io::ErrorKind::AlreadyExists => serde::Serializer::serialize_unit_variant(
serializer,
"ErrorKind",
9u32,
"AlreadyExists",
),
io::ErrorKind::WouldBlock => {
serde::Serializer::serialize_unit_variant(serializer, "ErrorKind", 10u32, "WouldBlock")
}
io::ErrorKind::InvalidInput => serde::Serializer::serialize_unit_variant(
serializer,
"ErrorKind",
11u32,
"InvalidInput",
),
io::ErrorKind::InvalidData => {
serde::Serializer::serialize_unit_variant(serializer, "ErrorKind", 12u32, "InvalidData")
}
io::ErrorKind::TimedOut => {
serde::Serializer::serialize_unit_variant(serializer, "ErrorKind", 13u32, "TimedOut")
}
io::ErrorKind::WriteZero => {
serde::Serializer::serialize_unit_variant(serializer, "ErrorKind", 14u32, "WriteZero")
}
io::ErrorKind::Interrupted => {
serde::Serializer::serialize_unit_variant(serializer, "ErrorKind", 15u32, "Interrupted")
}
io::ErrorKind::Other => {
serde::Serializer::serialize_unit_variant(serializer, "ErrorKind", 16u32, "Other")
}
io::ErrorKind::UnexpectedEof => serde::Serializer::serialize_unit_variant(
serializer,
"ErrorKind",
17u32,
"UnexpectedEof",
),
// #[non_exhaustive] is used on the definition of ErrorKind for future compatability
// That means match statements always need to match on _.
// The downside here is that rustc won't be able to warn us if io::ErrorKind another
// field is added to io::ErrorKind
_ => serde::Serializer::serialize_unit_variant(serializer, "ErrorKind", 16u32, "Other"),
}
}
// deserializer for io::Errorkind, originally auto-generated by serde-derive
fn deserialize_error_kind<'de, D>(deserializer: D) -> serde::export::Result<io::ErrorKind, D::Error>
where
D: serde::Deserializer<'de>,
{
#[allow(non_camel_case_types)]
enum Field {
field0,
field1,
field2,
field3,
field4,
field5,
field6,
field7,
field8,
field9,
field10,
field11,
field12,
field13,
field14,
field15,
field16,
field17,
}
struct FieldVisitor;
impl<'de> serde::de::Visitor<'de> for FieldVisitor {
type Value = Field;
fn expecting(
&self,
formatter: &mut serde::export::Formatter,
) -> serde::export::fmt::Result {
serde::export::Formatter::write_str(formatter, "variant identifier")
}
fn visit_u64<E>(self, value: u64) -> serde::export::Result<Self::Value, E>
where
E: serde::de::Error,
{
match value {
0u64 => serde::export::Ok(Field::field0),
1u64 => serde::export::Ok(Field::field1),
2u64 => serde::export::Ok(Field::field2),
3u64 => serde::export::Ok(Field::field3),
4u64 => serde::export::Ok(Field::field4),
5u64 => serde::export::Ok(Field::field5),
6u64 => serde::export::Ok(Field::field6),
7u64 => serde::export::Ok(Field::field7),
8u64 => serde::export::Ok(Field::field8),
9u64 => serde::export::Ok(Field::field9),
10u64 => serde::export::Ok(Field::field10),
11u64 => serde::export::Ok(Field::field11),
12u64 => serde::export::Ok(Field::field12),
13u64 => serde::export::Ok(Field::field13),
14u64 => serde::export::Ok(Field::field14),
15u64 => serde::export::Ok(Field::field15),
16u64 => serde::export::Ok(Field::field16),
17u64 => serde::export::Ok(Field::field17),
_ => serde::export::Err(serde::de::Error::invalid_value(
serde::de::Unexpected::Unsigned(value),
&"variant index 0 <= i < 18",
)),
}
}
fn visit_str<E>(self, value: &str) -> serde::export::Result<Self::Value, E>
where
E: serde::de::Error,
{
match value {
"NotFound" => serde::export::Ok(Field::field0),
"PermissionDenied" => serde::export::Ok(Field::field1),
"ConnectionRefused" => serde::export::Ok(Field::field2),
"ConnectionReset" => serde::export::Ok(Field::field3),
"ConnectionAborted" => serde::export::Ok(Field::field4),
"NotConnected" => serde::export::Ok(Field::field5),
"AddrInUse" => serde::export::Ok(Field::field6),
"AddrNotAvailable" => serde::export::Ok(Field::field7),
"BrokenPipe" => serde::export::Ok(Field::field8),
"AlreadyExists" => serde::export::Ok(Field::field9),
"WouldBlock" => serde::export::Ok(Field::field10),
"InvalidInput" => serde::export::Ok(Field::field11),
"InvalidData" => serde::export::Ok(Field::field12),
"TimedOut" => serde::export::Ok(Field::field13),
"WriteZero" => serde::export::Ok(Field::field14),
"Interrupted" => serde::export::Ok(Field::field15),
"Other" => serde::export::Ok(Field::field16),
"UnexpectedEof" => serde::export::Ok(Field::field17),
_ => serde::export::Err(serde::de::Error::unknown_variant(value, VARIANTS)),
}
}
fn visit_bytes<E>(self, value: &[u8]) -> serde::export::Result<Self::Value, E>
where
E: serde::de::Error,
{
match value {
b"NotFound" => serde::export::Ok(Field::field0),
b"PermissionDenied" => serde::export::Ok(Field::field1),
b"ConnectionRefused" => serde::export::Ok(Field::field2),
b"ConnectionReset" => serde::export::Ok(Field::field3),
b"ConnectionAborted" => serde::export::Ok(Field::field4),
b"NotConnected" => serde::export::Ok(Field::field5),
b"AddrInUse" => serde::export::Ok(Field::field6),
b"AddrNotAvailable" => serde::export::Ok(Field::field7),
b"BrokenPipe" => serde::export::Ok(Field::field8),
b"AlreadyExists" => serde::export::Ok(Field::field9),
b"WouldBlock" => serde::export::Ok(Field::field10),
b"InvalidInput" => serde::export::Ok(Field::field11),
b"InvalidData" => serde::export::Ok(Field::field12),
b"TimedOut" => serde::export::Ok(Field::field13),
b"WriteZero" => serde::export::Ok(Field::field14),
b"Interrupted" => serde::export::Ok(Field::field15),
b"Other" => serde::export::Ok(Field::field16),
b"UnexpectedEof" => serde::export::Ok(Field::field17),
_ => {
let value = &serde::export::from_utf8_lossy(value);
serde::export::Err(serde::de::Error::unknown_variant(value, VARIANTS))
}
}
}
}
impl<'de> serde::Deserialize<'de> for Field {
#[inline]
fn deserialize<D>(deserializer: D) -> serde::export::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
serde::Deserializer::deserialize_identifier(deserializer, FieldVisitor)
}
}
struct Visitor<'de> {
marker: serde::export::PhantomData<io::ErrorKind>,
lifetime: serde::export::PhantomData<&'de ()>,
}
impl<'de> serde::de::Visitor<'de> for Visitor<'de> {
type Value = io::ErrorKind;
fn expecting(
&self,
formatter: &mut serde::export::Formatter,
) -> serde::export::fmt::Result {
serde::export::Formatter::write_str(formatter, "enum io::ErrorKind")
}
fn visit_enum<A>(self, data: A) -> serde::export::Result<Self::Value, A::Error>
where
A: serde::de::EnumAccess<'de>,
{
match match serde::de::EnumAccess::variant(data) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
} {
(Field::field0, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::NotFound)
}
(Field::field1, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::PermissionDenied)
}
(Field::field2, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::ConnectionRefused)
}
(Field::field3, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::ConnectionReset)
}
(Field::field4, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::ConnectionAborted)
}
(Field::field5, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::NotConnected)
}
(Field::field6, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::AddrInUse)
}
(Field::field7, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::AddrNotAvailable)
}
(Field::field8, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::BrokenPipe)
}
(Field::field9, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::AlreadyExists)
}
(Field::field10, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::WouldBlock)
}
(Field::field11, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::InvalidInput)
}
(Field::field12, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::InvalidData)
}
(Field::field13, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::TimedOut)
}
(Field::field14, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::WriteZero)
}
(Field::field15, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::Interrupted)
}
(Field::field16, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::Other)
}
(Field::field17, variant) => {
match serde::de::VariantAccess::unit_variant(variant) {
serde::export::Ok(val) => val,
serde::export::Err(err) => {
return serde::export::Err(err);
}
};
serde::export::Ok(io::ErrorKind::UnexpectedEof)
}
}
}
}
const VARIANTS: &'static [&'static str] = &[
"NotFound",
"PermissionDenied",
"ConnectionRefused",
"ConnectionReset",
"ConnectionAborted",
"NotConnected",
"AddrInUse",
"AddrNotAvailable",
"BrokenPipe",
"AlreadyExists",
"WouldBlock",
"InvalidInput",
"InvalidData",
"TimedOut",
"WriteZero",
"Interrupted",
"Other",
"UnexpectedEof",
];
serde::Deserializer::deserialize_enum(
deserializer,
"ErrorKind",
VARIANTS,
Visitor {
marker: serde::export::PhantomData::<io::ErrorKind>,
lifetime: serde::export::PhantomData,
},
)
}

View file

@ -295,7 +295,7 @@ impl serde::Serialize for ChildNumber {
}
/// A BIP32 error
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum Error {
/// A pk->pk derivation was attempted on a hardened key
CannotDeriveFromHardenedKey,

View file

@ -29,7 +29,7 @@ lazy_static! {
}
/// An error that might occur during mnemonic decoding
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Error {
/// Invalid word encountered
BadWord(String),

View file

@ -40,7 +40,7 @@ use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
// Size of an identifier in bytes
pub const IDENTIFIER_SIZE: usize = 17;
#[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)]
#[derive(PartialEq, Eq, Clone, Debug)]
pub enum Error {
Secp(secp::Error),
KeyDerivation(extkey_bip32::Error),