diff --git a/Cargo.toml b/Cargo.toml index 3f3a7019..1fd8e5be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,8 @@ unproven = [] [dependencies] either = "1.5" xmltree = "0.8" -failure = "0.1" +anyhow = "1.0.19" +thiserror = "1.0.5" [dependencies.serde] version = "1.0" diff --git a/src/elementext.rs b/src/elementext.rs index 54624703..f7e6071d 100644 --- a/src/elementext.rs +++ b/src/elementext.rs @@ -4,25 +4,24 @@ use xmltree::Element; use crate::types::{BoolParse, Parse}; -use failure::ResultExt; use crate::error::*; /// Defines extensions for implementation over xmltree::Element pub trait ElementExt { - fn get_child_text_opt(&self, k: K) -> Result, SVDError> + fn get_child_text_opt(&self, k: K) -> Result> where String: PartialEq; - fn get_child_text(&self, k: K) -> Result + fn get_child_text(&self, k: K) -> Result where String: PartialEq, K: core::fmt::Display + Clone; - fn get_text(&self) -> Result; + fn get_text(&self) -> Result; - fn get_child_elem<'a>(&'a self, n: &str) -> Result<&'a Element, SVDError>; - fn get_child_u32(&self, n: &str) -> Result; - fn get_child_bool(&self, n: &str) -> Result; + fn get_child_elem<'a>(&'a self, n: &str) -> Result<&'a Element>; + fn get_child_u32(&self, n: &str) -> Result; + fn get_child_bool(&self, n: &str) -> Result; fn merge(&self, n: &Self) -> Self; @@ -31,7 +30,7 @@ pub trait ElementExt { /// Implements extensions for xmltree::Element impl ElementExt for Element { - fn get_child_text_opt(&self, k: K) -> Result, SVDError> + fn get_child_text_opt(&self, k: K) -> Result> where String: PartialEq, { @@ -41,44 +40,42 @@ impl ElementExt for Element { Ok(None) } } - fn get_child_text(&self, k: K) -> Result + fn get_child_text(&self, k: K) -> Result where String: PartialEq, K: core::fmt::Display + Clone, { self.get_child_text_opt(k.clone())? - .ok_or_else(|| SVDErrorKind::MissingTag(self.clone(), format!("{}", k)).into()) + .ok_or_else(|| SVDError::MissingTag(self.clone(), format!("{}", k)).into()) } /// Get text contained by an XML Element - fn get_text(&self) -> Result { + fn get_text(&self) -> Result { match self.text.as_ref() { Some(s) => Ok(s.clone()), - // FIXME: Doesn't look good because SVDErrorKind doesn't format by itself. We already + // FIXME: Doesn't look good because SVDError doesn't format by itself. We already // capture the element and this information can be used for getting the name // This would fix ParseError - None => Err(SVDErrorKind::EmptyTag(self.clone(), self.name.clone()).into()), + None => Err(SVDError::EmptyTag(self.clone(), self.name.clone()).into()), } } /// Get a named child element from an XML Element - fn get_child_elem<'a>(&'a self, n: &str) -> Result<&'a Element, SVDError> { + fn get_child_elem<'a>(&'a self, n: &str) -> Result<&'a Element> { match self.get_child(n) { Some(s) => Ok(s), - None => Err(SVDErrorKind::MissingTag(self.clone(), n.to_string()).into()), + None => Err(SVDError::MissingTag(self.clone(), n.to_string()).into()), } } /// Get a u32 value from a named child element - fn get_child_u32(&self, n: &str) -> Result { + fn get_child_u32(&self, n: &str) -> Result { let s = self.get_child_elem(n)?; - u32::parse(&s) - .context(SVDErrorKind::ParseError(self.clone())) - .map_err(|e| e.into()) + u32::parse(&s).context(SVDError::ParseError(self.clone())) } /// Get a bool value from a named child element - fn get_child_bool(&self, n: &str) -> Result { + fn get_child_bool(&self, n: &str) -> Result { let s = self.get_child_elem(n)?; BoolParse::parse(s) } diff --git a/src/error.rs b/src/error.rs index 096cc377..caaa7905 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,63 +1,46 @@ //! SVD Errors. //! This module defines error types and messages for SVD parsing and encoding -use core::fmt::{self, Display}; -use failure::{Backtrace, Context, Fail}; -use xmltree::{Element, ParseError}; +pub use anyhow::{Context, Result}; +use xmltree::Element; -#[derive(Debug)] -pub struct SVDError { - inner: Context, -} - -// TODO: Expand and make more complex output possible. -// We can use the `Element` to output name (if available) and etc. #[allow(clippy::large_enum_variant)] -#[derive(Clone, Debug, PartialEq, Eq, Fail)] -pub enum SVDErrorKind { - #[fail(display = "Unknown endianness `{}`", _0)] +#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)] +pub enum SVDError { + #[error("Unknown endianness `{0}`")] UnknownEndian(String), // TODO: Needs context // TODO: Better name - #[fail(display = "Expected a <{}> tag, found none", _1)] + #[error("Expected a <{1}> tag, found none")] MissingTag(Element, String), - #[fail(display = "Expected content in <{}> tag, found none", _1)] + #[error("Expected content in <{1}> tag, found none")] EmptyTag(Element, String), - #[fail(display = "ParseError")] + #[error("ParseError")] ParseError(Element), - #[fail(display = "NameMismatch")] + #[error("NameMismatch")] NameMismatch(Element), - #[fail(display = "unknown access variant '{}' found", _1)] + #[error("unknown access variant '{1}' found")] UnknownAccessType(Element, String), - #[fail(display = "Bit range invalid, {:?}", _1)] + #[error("Bit range invalid, {1:?}")] InvalidBitRange(Element, InvalidBitRange), - #[fail(display = "Unknown write constraint")] + #[error("Unknown write constraint")] UnknownWriteConstraint(Element), - #[fail(display = "Multiple wc found")] + #[error("Multiple wc found")] MoreThanOneWriteConstraint(Element), - #[fail(display = "Unknown usage variant")] + #[error("Unknown usage variant")] UnknownUsageVariant(Element), - #[fail(display = "Expected a <{}>, found ...", _1)] + #[error("Expected a <{1}>, found ...")] NotExpectedTag(Element, String), - #[fail( - display = "Invalid RegisterCluster (expected register or cluster), found {}", - _1 - )] + #[error("Invalid RegisterCluster (expected register or cluster), found {1}")] InvalidRegisterCluster(Element, String), - #[fail(display = "Invalid modifiedWriteValues variant, found {}", _1)] + #[error("Invalid modifiedWriteValues variant, found {1}")] InvalidModifiedWriteValues(Element, String), - #[fail( - display = "The content of the element could not be parsed to a boolean value {}: {}", - _1, _2 - )] + #[error("The content of the element could not be parsed to a boolean value {1}: {2}")] InvalidBooleanValue(Element, String, core::str::ParseBoolError), - #[fail(display = "encoding method not implemented for svd object {}", _0)] + #[error("encoding method not implemented for svd object {0}")] EncodeNotImplemented(String), - #[fail(display = "Error parsing SVD XML")] + #[error("Error parsing SVD XML")] FileParseError, - // FIXME: Should not be used, only for prototyping - #[fail(display = "{}", _0)] - Other(String), } // TODO: Consider making into an Error @@ -67,47 +50,3 @@ pub enum InvalidBitRange { ParseError, MsbLsb, } - -impl Fail for SVDError { - fn cause(&self) -> Option<&dyn Fail> { - self.inner.cause() - } - - fn backtrace(&self) -> Option<&Backtrace> { - self.inner.backtrace() - } -} - -impl Display for SVDError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt(&self.inner, f) - } -} - -impl SVDError { - pub fn kind(&self) -> SVDErrorKind { - self.inner.get_context().clone() - } -} - -impl From for SVDError { - fn from(kind: SVDErrorKind) -> SVDError { - SVDError { - inner: Context::new(kind), - } - } -} - -impl From> for SVDError { - fn from(inner: Context) -> SVDError { - SVDError { inner } - } -} - -impl From for SVDError { - fn from(e: ParseError) -> SVDError { - SVDError { - inner: e.context(SVDErrorKind::FileParseError), - } - } -} diff --git a/src/lib.rs b/src/lib.rs index a0580d2f..d56d48f1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,7 @@ pub mod svd; pub use svd::*; // Error defines SVD error types pub mod error; -use error::SVDError; +use anyhow::Result; // Parse defines parsing interfaces pub mod parse; use parse::Parse; @@ -54,7 +54,7 @@ pub mod derive_from; pub use derive_from::DeriveFrom; /// Parses the contents of an SVD (XML) string -pub fn parse(xml: &str) -> Result { +pub fn parse(xml: &str) -> Result { let xml = trim_utf8_bom(xml); let tree = Element::parse(xml.as_bytes())?; Device::parse(&tree) @@ -62,7 +62,7 @@ pub fn parse(xml: &str) -> Result { /// Encodes a device object to an SVD (XML) string #[cfg(feature = "unproven")] -pub fn encode(d: &Device) -> Result { +pub fn encode(d: &Device) -> Result { let root = d.encode()?; let mut wr = Vec::new(); root.write(&mut wr).unwrap(); @@ -98,7 +98,10 @@ pub(crate) fn new_element(name: &str, text: Option) -> Element { #[cfg(test)] #[cfg(feature = "unproven")] pub fn run_test< - T: Parse + Encode + core::fmt::Debug + PartialEq, + T: Parse + + Encode + + core::fmt::Debug + + PartialEq, >( tests: &[(T, &str)], ) { diff --git a/src/parse.rs b/src/parse.rs index 087882fc..7a20a593 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -3,8 +3,6 @@ use xmltree::Element; -use crate::error::*; - /// Parse trait allows SVD objects to be parsed from XML elements. pub trait Parse { /// Object returned by parse method @@ -18,9 +16,9 @@ pub trait Parse { /// Parses an optional child element with the provided name and Parse function /// Returns an none if the child doesn't exist, Ok(Some(e)) if parsing succeeds, /// and Err() if parsing fails. -pub fn optional<'a, T>(n: &str, e: &'a Element) -> Result, SVDError> +pub fn optional<'a, T>(n: &str, e: &'a Element) -> anyhow::Result> where - T: Parse, + T: Parse, { let child = match e.get_child(n) { Some(c) => c, diff --git a/src/svd/access.rs b/src/svd/access.rs index 740a91ef..1929b80b 100644 --- a/src/svd/access.rs +++ b/src/svd/access.rs @@ -20,9 +20,9 @@ pub enum Access { impl Parse for Access { type Object = Access; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { let text = tree.get_text()?; match &text[..] { @@ -31,16 +31,16 @@ impl Parse for Access { "read-writeOnce" => Ok(Access::ReadWriteOnce), "write-only" => Ok(Access::WriteOnly), "writeOnce" => Ok(Access::WriteOnce), - _ => Err(SVDErrorKind::UnknownAccessType(tree.clone(), text).into()), + _ => Err(SVDError::UnknownAccessType(tree.clone(), text).into()), } } } #[cfg(feature = "unproven")] impl Encode for Access { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { let text = match *self { Access::ReadOnly => String::from("read-only"), Access::ReadWrite => String::from("read-write"), diff --git a/src/svd/addressblock.rs b/src/svd/addressblock.rs index f0e24ed5..88bb1d21 100644 --- a/src/svd/addressblock.rs +++ b/src/svd/addressblock.rs @@ -8,7 +8,7 @@ use crate::types::Parse; #[cfg(feature = "unproven")] use crate::encode::Encode; -use crate::error::SVDError; +use crate::error::*; #[cfg(feature = "unproven")] use crate::new_element; @@ -22,9 +22,9 @@ pub struct AddressBlock { impl Parse for AddressBlock { type Object = AddressBlock; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { Ok(AddressBlock { offset: tree.get_child_u32("offset")?, size: tree.get_child_u32("size")?, @@ -35,9 +35,9 @@ impl Parse for AddressBlock { #[cfg(feature = "unproven")] impl Encode for AddressBlock { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { Ok(Element { prefix: None, namespace: None, diff --git a/src/svd/bitrange.rs b/src/svd/bitrange.rs index d4f92cd5..01f525ca 100644 --- a/src/svd/bitrange.rs +++ b/src/svd/bitrange.rs @@ -1,4 +1,3 @@ -use failure::ResultExt; use xmltree::Element; use crate::error::*; @@ -33,26 +32,26 @@ pub enum BitRangeType { impl Parse for BitRange { type Object = BitRange; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { let (end, start, range_type): (u32, u32, BitRangeType) = if let Some(range) = tree.get_child("bitRange") { let text = range .text .as_ref() - .ok_or_else(|| SVDErrorKind::Other("text missing".to_string()))?; // TODO: Make into a proper error, text empty or something similar - // TODO: If the `InvalidBitRange` enum was an error we could context into here somehow so that - // the output would be similar to the parse error + .ok_or_else(|| anyhow::anyhow!("text missing"))?; // TODO: Make into a proper error, text empty or something similar + // TODO: If the `InvalidBitRange` enum was an error we could context into here somehow so that + // the output would be similar to the parse error if !text.starts_with('[') { return Err( - SVDErrorKind::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax).into(), + SVDError::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax).into(), ); // TODO: Maybe have a MissingOpen/MissingClosing variant } if !text.ends_with(']') { return Err( - SVDErrorKind::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax).into(), + SVDError::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax).into(), ); // TODO: Maybe have a MissingOpen/MissingClosing variant } @@ -61,20 +60,20 @@ impl Parse for BitRange { parts .next() .ok_or_else(|| { - SVDErrorKind::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax) + SVDError::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax) })? .parse::() - .context(SVDErrorKind::InvalidBitRange( + .context(SVDError::InvalidBitRange( tree.clone(), InvalidBitRange::ParseError, ))?, parts .next() .ok_or_else(|| { - SVDErrorKind::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax) + SVDError::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax) })? .parse::() - .context(SVDErrorKind::InvalidBitRange( + .context(SVDError::InvalidBitRange( tree.clone(), InvalidBitRange::ParseError, ))?, @@ -84,11 +83,11 @@ impl Parse for BitRange { } else if let (Some(lsb), Some(msb)) = (tree.get_child("lsb"), tree.get_child("msb")) { ( // TODO: `u32::parse` should not hide it's errors - u32::parse(msb).context(SVDErrorKind::InvalidBitRange( + u32::parse(msb).context(SVDError::InvalidBitRange( tree.clone(), InvalidBitRange::MsbLsb, ))?, - u32::parse(lsb).context(SVDErrorKind::InvalidBitRange( + u32::parse(lsb).context(SVDError::InvalidBitRange( tree.clone(), InvalidBitRange::MsbLsb, ))?, @@ -103,11 +102,11 @@ impl Parse for BitRange { return Ok(BitRange { // TODO: capture that error comes from offset/width tag // TODO: `u32::parse` should not hide it's errors - offset: u32::parse(offset).context(SVDErrorKind::InvalidBitRange( + offset: u32::parse(offset).context(SVDError::InvalidBitRange( tree.clone(), InvalidBitRange::ParseError, ))?, - width: u32::parse(width).context(SVDErrorKind::InvalidBitRange( + width: u32::parse(width).context(SVDError::InvalidBitRange( tree.clone(), InvalidBitRange::ParseError, ))?, @@ -115,9 +114,7 @@ impl Parse for BitRange { }) ) } else { - return Err( - SVDErrorKind::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax).into(), - ); + return Err(SVDError::InvalidBitRange(tree.clone(), InvalidBitRange::Syntax).into()); }; Ok(BitRange { @@ -130,7 +127,7 @@ impl Parse for BitRange { #[cfg(feature = "unproven")] impl BitRange { // TODO: Encode method differs from Encode trait as it acts on a set of possible children, create an interface or decide how to better do this - pub fn encode(&self) -> Result, SVDError> { + pub fn encode(&self) -> Result> { match self.range_type { BitRangeType::BitRange => Ok(vec![new_element( "bitRange", diff --git a/src/svd/cluster.rs b/src/svd/cluster.rs index 6b0ee1ab..a313ac15 100644 --- a/src/svd/cluster.rs +++ b/src/svd/cluster.rs @@ -30,8 +30,9 @@ impl Deref for Cluster { impl Parse for Cluster { type Object = Cluster; - type Error = SVDError; - fn parse(tree: &Element) -> Result { + type Error = anyhow::Error; + + fn parse(tree: &Element) -> Result { assert_eq!(tree.name, "cluster"); let info = ClusterInfo::parse(tree)?; @@ -40,17 +41,13 @@ impl Parse for Cluster { let array_info = DimElement::parse(tree)?; if !info.name.contains("%s") { // TODO: replace with real error - return Err(SVDError::from(SVDErrorKind::Other( - "Cluster name invalid".to_string(), - ))); + anyhow::bail!("Cluster name invalid"); } if let Some(indices) = &array_info.dim_index { if array_info.dim as usize != indices.len() { // TODO: replace with real error - return Err(SVDError::from(SVDErrorKind::Other( - "Cluster index length mismatch".to_string(), - ))); + anyhow::bail!("Cluster index length mismatch"); } } @@ -63,9 +60,10 @@ impl Parse for Cluster { #[cfg(feature = "unproven")] impl Encode for Cluster { - type Error = SVDError; + type Error = anyhow::Error; + // TODO: support Cluster encoding - fn encode(&self) -> Result { + fn encode(&self) -> Result { match self { Cluster::Single(i) => i.encode(), Cluster::Array(i, a) => { diff --git a/src/svd/clusterinfo.rs b/src/svd/clusterinfo.rs index fadc7d7e..9e9af1f8 100644 --- a/src/svd/clusterinfo.rs +++ b/src/svd/clusterinfo.rs @@ -8,7 +8,7 @@ use crate::encode::{Encode, EncodeChildren}; #[cfg(feature = "unproven")] use crate::new_element; -use crate::error::SVDError; +use crate::error::*; use crate::svd::{registercluster::RegisterCluster, registerproperties::RegisterProperties}; #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] @@ -27,9 +27,9 @@ pub struct ClusterInfo { impl Parse for ClusterInfo { type Object = ClusterInfo; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { Ok(ClusterInfo { name: tree.get_child_text("name")?, // TODO: Handle naming of cluster derived_from: tree.attributes.get("derivedFrom").map(|s| s.to_owned()), @@ -53,8 +53,9 @@ impl Parse for ClusterInfo { #[cfg(feature = "unproven")] impl Encode for ClusterInfo { - type Error = SVDError; - fn encode(&self) -> Result { + type Error = anyhow::Error; + + fn encode(&self) -> Result { let mut e = new_element("cluster", None); if let Some(v) = &self.derived_from { diff --git a/src/svd/cpu.rs b/src/svd/cpu.rs index bf4e6e82..acdaae2b 100644 --- a/src/svd/cpu.rs +++ b/src/svd/cpu.rs @@ -29,11 +29,11 @@ pub struct Cpu { impl Parse for Cpu { type Object = Cpu; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { if tree.name != "cpu" { - return Err(SVDErrorKind::NameMismatch(tree.clone()).into()); + return Err(SVDError::NameMismatch(tree.clone()).into()); } Ok(Cpu { @@ -51,9 +51,9 @@ impl Parse for Cpu { #[cfg(feature = "unproven")] impl Encode for Cpu { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { Ok(Element { prefix: None, namespace: None, diff --git a/src/svd/device.rs b/src/svd/device.rs index cea30c32..73bcc754 100644 --- a/src/svd/device.rs +++ b/src/svd/device.rs @@ -8,7 +8,7 @@ use crate::types::Parse; #[cfg(feature = "unproven")] use crate::encode::{Encode, EncodeChildren}; -use crate::error::SVDError; +use crate::error::*; #[cfg(feature = "unproven")] use crate::new_element; use crate::svd::{cpu::Cpu, peripheral::Peripheral, registerproperties::RegisterProperties}; @@ -31,10 +31,10 @@ pub struct Device { impl Parse for Device { type Object = Device; - type Error = SVDError; + type Error = anyhow::Error; /// Parses a SVD file - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { Ok(Device { name: tree.get_child_text("name")?, schema_version: tree.attributes.get("schemaVersion").cloned(), @@ -60,9 +60,9 @@ impl Parse for Device { #[cfg(feature = "unproven")] impl Encode for Device { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { let mut elem = Element { prefix: None, namespace: None, diff --git a/src/svd/dimelement.rs b/src/svd/dimelement.rs index b44ce910..fe545717 100644 --- a/src/svd/dimelement.rs +++ b/src/svd/dimelement.rs @@ -8,7 +8,7 @@ use crate::encode::Encode; #[cfg(feature = "unproven")] use crate::new_element; -use crate::error::SVDError; +use crate::error::*; #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[derive(Clone, Debug, PartialEq)] @@ -22,9 +22,9 @@ pub struct DimElement { impl Parse for DimElement { type Object = DimElement; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { Ok(DimElement { dim: tree.get_child_u32("dim")?, dim_increment: tree.get_child_u32("dimIncrement")?, @@ -36,9 +36,9 @@ impl Parse for DimElement { #[cfg(feature = "unproven")] impl Encode for DimElement { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { let mut e = new_element("dimElement", None); e.children diff --git a/src/svd/endian.rs b/src/svd/endian.rs index dae62233..977798c0 100644 --- a/src/svd/endian.rs +++ b/src/svd/endian.rs @@ -21,9 +21,9 @@ pub enum Endian { impl Parse for Endian { type Object = Endian; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { let text = tree.get_text()?; match &text[..] { @@ -31,16 +31,16 @@ impl Parse for Endian { "big" => Ok(Endian::Big), "selectable" => Ok(Endian::Selectable), "other" => Ok(Endian::Other), - s => Err(SVDErrorKind::UnknownEndian(s.into()).into()), + s => Err(SVDError::UnknownEndian(s.into()).into()), } } } #[cfg(feature = "unproven")] impl Encode for Endian { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { let text = match *self { Endian::Little => String::from("little"), Endian::Big => String::from("big"), diff --git a/src/svd/enumeratedvalue.rs b/src/svd/enumeratedvalue.rs index 9afece19..3b708c63 100644 --- a/src/svd/enumeratedvalue.rs +++ b/src/svd/enumeratedvalue.rs @@ -3,7 +3,6 @@ use std::collections::HashMap; use crate::elementext::ElementExt; use crate::parse; -use failure::ResultExt; use xmltree::Element; #[cfg(feature = "unproven")] @@ -24,7 +23,7 @@ pub struct EnumeratedValue { pub(crate) _extensible: (), } impl EnumeratedValue { - fn _parse(tree: &Element, name: String) -> Result { + fn _parse(tree: &Element, name: String) -> Result { Ok(EnumeratedValue { name, description: tree.get_child_text_opt("description")?, @@ -38,29 +37,25 @@ impl EnumeratedValue { } impl Parse for EnumeratedValue { type Object = EnumeratedValue; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { if tree.name != "enumeratedValue" { return Err( - SVDErrorKind::NotExpectedTag(tree.clone(), "enumeratedValue".to_string()).into(), + SVDError::NotExpectedTag(tree.clone(), "enumeratedValue".to_string()).into(), ); } let name = tree.get_child_text("name")?; EnumeratedValue::_parse(tree, name.clone()) - .context(SVDErrorKind::Other(format!( - "In enumerated value `{}`", - name - ))) - .map_err(|e| e.into()) + .context(format!("In enumerated value `{}`", name)) } } #[cfg(feature = "unproven")] impl Encode for EnumeratedValue { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { let mut base = Element { prefix: None, namespace: None, diff --git a/src/svd/enumeratedvalues.rs b/src/svd/enumeratedvalues.rs index 8838e3ac..7642fd69 100644 --- a/src/svd/enumeratedvalues.rs +++ b/src/svd/enumeratedvalues.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use crate::elementext::ElementExt; -use failure::ResultExt; use xmltree::Element; #[cfg(feature = "unproven")] @@ -27,9 +26,9 @@ pub struct EnumeratedValues { impl Parse for EnumeratedValues { type Object = EnumeratedValues; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { assert_eq!(tree.name, "enumeratedValues"); let derived_from = tree.attributes.get("derivedFrom").map(|s| s.to_owned()); let is_derived = derived_from.is_some(); @@ -50,22 +49,19 @@ impl Parse for EnumeratedValues { .enumerate() .map(|(e, t)| { if t.name == "enumeratedValue" { - EnumeratedValue::parse(t).context(SVDErrorKind::Other(format!( - "Parsing enumerated value #{}", - e - ))) + EnumeratedValue::parse(t) + .context(format!("Parsing enumerated value #{}", e)) } else { - Err(SVDErrorKind::NotExpectedTag( - t.clone(), - "enumeratedValue".to_string(), + Err( + SVDError::NotExpectedTag(t.clone(), "enumeratedValue".to_string()) + .into(), ) - .into()) } }) .collect(); let values = values?; if values.is_empty() && !is_derived { - return Err(SVDErrorKind::EmptyTag(tree.clone(), tree.name.clone()).into()); + return Err(SVDError::EmptyTag(tree.clone(), tree.name.clone()).into()); } values }, @@ -76,9 +72,9 @@ impl Parse for EnumeratedValues { #[cfg(feature = "unproven")] impl Encode for EnumeratedValues { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { let mut base = Element { prefix: None, namespace: None, @@ -174,7 +170,7 @@ mod tests { #[test] fn valid_children() { - fn parse(contents: String) -> Result { + fn parse(contents: String) -> Result { let example = String::from("") + &contents + ""; let tree = Element::parse(example.as_bytes()).unwrap(); EnumeratedValues::parse(&tree) diff --git a/src/svd/field.rs b/src/svd/field.rs index 0182247d..1310e1b5 100644 --- a/src/svd/field.rs +++ b/src/svd/field.rs @@ -8,7 +8,7 @@ use crate::types::Parse; use crate::elementext::ElementExt; #[cfg(feature = "unproven")] use crate::encode::Encode; -use crate::error::SVDError; +use crate::error::*; use crate::svd::{dimelement::DimElement, fieldinfo::FieldInfo}; #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] @@ -31,9 +31,9 @@ impl Deref for Field { impl Parse for Field { type Object = Field; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { assert_eq!(tree.name, "field"); let info = FieldInfo::parse(tree)?; @@ -53,9 +53,9 @@ impl Parse for Field { #[cfg(feature = "unproven")] impl Encode for Field { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { match self { Field::Single(info) => info.encode(), Field::Array(info, array_info) => { diff --git a/src/svd/fieldinfo.rs b/src/svd/fieldinfo.rs index 06f5f1aa..a1ea8dbb 100644 --- a/src/svd/fieldinfo.rs +++ b/src/svd/fieldinfo.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use crate::elementext::ElementExt; -use failure::ResultExt; use xmltree::Element; #[cfg(feature = "unproven")] @@ -35,20 +34,19 @@ pub struct FieldInfo { impl Parse for FieldInfo { type Object = FieldInfo; - type Error = SVDError; - fn parse(tree: &Element) -> Result { + type Error = anyhow::Error; + + fn parse(tree: &Element) -> Result { if tree.name != "field" { - return Err(SVDErrorKind::NotExpectedTag(tree.clone(), "field".to_string()).into()); + return Err(SVDError::NotExpectedTag(tree.clone(), "field".to_string()).into()); } let name = tree.get_child_text("name")?; - FieldInfo::_parse(tree, name.clone()) - .context(SVDErrorKind::Other(format!("In field `{}`", name))) - .map_err(|e| e.into()) + FieldInfo::_parse(tree, name.clone()).context(format!("In field `{}`", name)) } } impl FieldInfo { - fn _parse(tree: &Element, name: String) -> Result { + fn _parse(tree: &Element, name: String) -> Result { Ok(FieldInfo { name, derived_from: tree.attributes.get("derivedFrom").map(|s| s.to_owned()), @@ -76,8 +74,9 @@ impl FieldInfo { #[cfg(feature = "unproven")] impl Encode for FieldInfo { - type Error = SVDError; - fn encode(&self) -> Result { + type Error = anyhow::Error; + + fn encode(&self) -> Result { let mut children = vec![new_element("name", Some(self.name.clone()))]; if let Some(description) = &self.description { @@ -106,7 +105,7 @@ impl Encode for FieldInfo { elem.children.push(v.encode()?); }; - let enumerated_values: Result, SVDError> = + let enumerated_values: Result> = self.enumerated_values.iter().map(|v| v.encode()).collect(); elem.children.append(&mut enumerated_values?); diff --git a/src/svd/interrupt.rs b/src/svd/interrupt.rs index 98ea3834..f680d270 100644 --- a/src/svd/interrupt.rs +++ b/src/svd/interrupt.rs @@ -1,7 +1,6 @@ #[cfg(feature = "unproven")] use std::collections::HashMap; -use failure::ResultExt; use xmltree::Element; use crate::elementext::ElementExt; @@ -22,7 +21,7 @@ pub struct Interrupt { } impl Interrupt { - fn _parse(tree: &Element, name: String) -> Result { + fn _parse(tree: &Element, name: String) -> Result { Ok(Interrupt { name, description: tree.get_child_text_opt("description")?, @@ -33,23 +32,22 @@ impl Interrupt { impl Parse for Interrupt { type Object = Interrupt; - type Error = SVDError; - fn parse(tree: &Element) -> Result { + type Error = anyhow::Error; + + fn parse(tree: &Element) -> Result { if tree.name != "interrupt" { - return Err(SVDErrorKind::NotExpectedTag(tree.clone(), "interrupt".to_string()).into()); + return Err(SVDError::NotExpectedTag(tree.clone(), "interrupt".to_string()).into()); } let name = tree.get_child_text("name")?; - Interrupt::_parse(tree, name.clone()) - .context(SVDErrorKind::Other(format!("In interrupt `{}`", name))) - .map_err(|e| e.into()) + Interrupt::_parse(tree, name.clone()).context(format!("In interrupt `{}`", name)) } } #[cfg(feature = "unproven")] impl Encode for Interrupt { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { Ok(Element { prefix: None, namespace: None, diff --git a/src/svd/modifiedwritevalues.rs b/src/svd/modifiedwritevalues.rs index 0da6300f..3ec052ce 100644 --- a/src/svd/modifiedwritevalues.rs +++ b/src/svd/modifiedwritevalues.rs @@ -25,9 +25,9 @@ pub enum ModifiedWriteValues { impl Parse for ModifiedWriteValues { type Object = ModifiedWriteValues; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { use self::ModifiedWriteValues::*; let text = tree.get_text()?; @@ -41,18 +41,16 @@ impl Parse for ModifiedWriteValues { "clear" => Clear, "set" => Set, "modify" => Modify, - s => { - return Err(SVDErrorKind::InvalidModifiedWriteValues(tree.clone(), s.into()).into()) - } + s => return Err(SVDError::InvalidModifiedWriteValues(tree.clone(), s.into()).into()), }) } } #[cfg(feature = "unproven")] impl Encode for ModifiedWriteValues { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { use self::ModifiedWriteValues::*; let v = match *self { OneToClear => "oneToClear", diff --git a/src/svd/peripheral.rs b/src/svd/peripheral.rs index 58da4200..57cc018f 100644 --- a/src/svd/peripheral.rs +++ b/src/svd/peripheral.rs @@ -5,7 +5,6 @@ use xmltree::Element; use crate::elementext::ElementExt; use crate::parse; -use failure::ResultExt; #[cfg(feature = "unproven")] use crate::encode::{Encode, EncodeChildren}; @@ -13,7 +12,7 @@ use crate::encode::{Encode, EncodeChildren}; use crate::new_element; use crate::types::Parse; -use crate::error::{SVDError, SVDErrorKind}; +use crate::error::*; use crate::svd::{ addressblock::AddressBlock, interrupt::Interrupt, registercluster::RegisterCluster, registerproperties::RegisterProperties, @@ -40,23 +39,19 @@ pub struct Peripheral { impl Parse for Peripheral { type Object = Peripheral; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { if tree.name != "peripheral" { - return Err( - SVDErrorKind::NotExpectedTag(tree.clone(), "peripheral".to_string()).into(), - ); + return Err(SVDError::NotExpectedTag(tree.clone(), "peripheral".to_string()).into()); } let name = tree.get_child_text("name")?; - Peripheral::_parse(tree, name.clone()) - .context(SVDErrorKind::Other(format!("In peripheral `{}`", name))) - .map_err(|e| e.into()) + Peripheral::_parse(tree, name.clone()).context(format!("In peripheral `{}`", name)) } } impl Peripheral { - fn _parse(tree: &Element, name: String) -> Result { + fn _parse(tree: &Element, name: String) -> Result { Ok(Peripheral { name, version: tree.get_child_text_opt("version")?, @@ -71,10 +66,7 @@ impl Peripheral { .iter() .filter(|t| t.name == "interrupt") .enumerate() - .map(|(e, i)| { - Interrupt::parse(i) - .context(SVDErrorKind::Other(format!("Parsing interrupt #{}", e))) - }) + .map(|(e, i)| Interrupt::parse(i).context(format!("Parsing interrupt #{}", e))) .collect(); interrupt? }, @@ -97,9 +89,9 @@ impl Peripheral { #[cfg(feature = "unproven")] impl Encode for Peripheral { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { let mut elem = Element { prefix: None, namespace: None, diff --git a/src/svd/register.rs b/src/svd/register.rs index 05b616b7..067396bd 100644 --- a/src/svd/register.rs +++ b/src/svd/register.rs @@ -8,8 +8,8 @@ use crate::types::Parse; use crate::elementext::ElementExt; #[cfg(feature = "unproven")] use crate::encode::Encode; -use crate::error::SVDError; use crate::svd::{dimelement::DimElement, registerinfo::RegisterInfo}; +use anyhow::Result; #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[derive(Clone, Debug, PartialEq)] @@ -31,9 +31,9 @@ impl Deref for Register { impl Parse for Register { type Object = Register; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { assert_eq!(tree.name, "register"); let info = RegisterInfo::parse(tree)?; @@ -53,9 +53,9 @@ impl Parse for Register { #[cfg(feature = "unproven")] impl Encode for Register { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { match self { Register::Single(info) => info.encode(), Register::Array(info, array_info) => { diff --git a/src/svd/registercluster.rs b/src/svd/registercluster.rs index e810e170..fce56d2f 100644 --- a/src/svd/registercluster.rs +++ b/src/svd/registercluster.rs @@ -5,7 +5,7 @@ use crate::types::Parse; #[cfg(feature = "unproven")] use crate::encode::Encode; -use crate::error::{SVDError, SVDErrorKind}; +use crate::error::*; use crate::svd::{cluster::Cluster, register::Register}; #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] @@ -29,25 +29,24 @@ impl From for RegisterCluster { impl Parse for RegisterCluster { type Object = RegisterCluster; - type Error = SVDError; - fn parse(tree: &Element) -> Result { + type Error = anyhow::Error; + + fn parse(tree: &Element) -> Result { if tree.name == "register" { Ok(RegisterCluster::Register(Register::parse(tree)?)) } else if tree.name == "cluster" { Ok(RegisterCluster::Cluster(Cluster::parse(tree)?)) } else { - Err(SVDError::from(SVDErrorKind::InvalidRegisterCluster( - tree.clone(), - tree.name.clone(), - ))) + Err(SVDError::InvalidRegisterCluster(tree.clone(), tree.name.clone()).into()) } } } #[cfg(feature = "unproven")] impl Encode for RegisterCluster { - type Error = SVDError; - fn encode(&self) -> Result { + type Error = anyhow::Error; + + fn encode(&self) -> Result { match self { RegisterCluster::Register(r) => r.encode(), RegisterCluster::Cluster(c) => c.encode(), diff --git a/src/svd/registerinfo.rs b/src/svd/registerinfo.rs index a6f16989..e83f80d8 100644 --- a/src/svd/registerinfo.rs +++ b/src/svd/registerinfo.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use crate::elementext::ElementExt; -use failure::ResultExt; use xmltree::Element; #[cfg(feature = "unproven")] @@ -41,18 +40,16 @@ pub struct RegisterInfo { impl Parse for RegisterInfo { type Object = RegisterInfo; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { let name = tree.get_child_text("name")?; - RegisterInfo::_parse(tree, name.clone()) - .context(SVDErrorKind::Other(format!("In register `{}`", name))) - .map_err(|e| e.into()) + RegisterInfo::_parse(tree, name.clone()).context(format!("In register `{}`", name)) } } impl RegisterInfo { - fn _parse(tree: &Element, name: String) -> Result { + fn _parse(tree: &Element, name: String) -> Result { let properties = RegisterProperties::parse(tree)?; Ok(RegisterInfo { name, @@ -71,10 +68,7 @@ impl RegisterInfo { .children .iter() .enumerate() - .map(|(e, t)| { - Field::parse(t) - .context(SVDErrorKind::Other(format!("Parsing field #{}", e))) - }) + .map(|(e, t)| Field::parse(t).context(format!("Parsing field #{}", e))) .collect(); Some(fs?) } else { @@ -93,8 +87,9 @@ impl RegisterInfo { #[cfg(feature = "unproven")] impl Encode for RegisterInfo { - type Error = SVDError; - fn encode(&self) -> Result { + type Error = anyhow::Error; + + fn encode(&self) -> Result { let mut elem = Element { prefix: None, namespace: None, @@ -152,7 +147,7 @@ impl Encode for RegisterInfo { let children = v .iter() .map(Field::encode) - .collect::, SVDError>>()?; + .collect::>>()?; if !children.is_empty() { let fields = Element { prefix: None, diff --git a/src/svd/registerproperties.rs b/src/svd/registerproperties.rs index d1f06725..5e4d773d 100644 --- a/src/svd/registerproperties.rs +++ b/src/svd/registerproperties.rs @@ -26,9 +26,9 @@ pub struct RegisterProperties { impl Parse for RegisterProperties { type Object = RegisterProperties; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { Ok(RegisterProperties { size: parse::optional::("size", tree)?, reset_value: parse::optional::("resetValue", tree)?, @@ -41,8 +41,9 @@ impl Parse for RegisterProperties { #[cfg(feature = "unproven")] impl EncodeChildren for RegisterProperties { - type Error = SVDError; - fn encode(&self) -> Result, SVDError> { + type Error = anyhow::Error; + + fn encode(&self) -> Result> { let mut children = Vec::new(); if let Some(v) = &self.size { diff --git a/src/svd/usage.rs b/src/svd/usage.rs index cba0a248..5b0159d3 100644 --- a/src/svd/usage.rs +++ b/src/svd/usage.rs @@ -19,25 +19,25 @@ pub enum Usage { impl Parse for Usage { type Object = Usage; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { let text = tree.get_text()?; match &text[..] { "read" => Ok(Usage::Read), "write" => Ok(Usage::Write), "read-write" => Ok(Usage::ReadWrite), - _ => Err(SVDErrorKind::UnknownUsageVariant(tree.clone()).into()), + _ => Err(SVDError::UnknownUsageVariant(tree.clone()).into()), } } } #[cfg(feature = "unproven")] impl Encode for Usage { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { let text = match *self { Usage::Read => String::from("read"), Usage::Write => String::from("write"), diff --git a/src/svd/writeconstraint.rs b/src/svd/writeconstraint.rs index b3cdc62a..06967362 100644 --- a/src/svd/writeconstraint.rs +++ b/src/svd/writeconstraint.rs @@ -28,9 +28,9 @@ pub struct WriteConstraintRange { impl Parse for WriteConstraint { type Object = WriteConstraint; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { if tree.children.len() == 1 { let field = &tree.children[0].name; // Write constraint can only be one of the following @@ -44,19 +44,19 @@ impl Parse for WriteConstraint { "range" => Ok(WriteConstraint::Range(WriteConstraintRange::parse( tree.get_child_elem(field.as_ref())?, )?)), - _ => Err(SVDErrorKind::UnknownWriteConstraint(tree.clone()).into()), + _ => Err(SVDError::UnknownWriteConstraint(tree.clone()).into()), } } else { - Err(SVDErrorKind::MoreThanOneWriteConstraint(tree.clone()).into()) + Err(SVDError::MoreThanOneWriteConstraint(tree.clone()).into()) } } } #[cfg(feature = "unproven")] impl Encode for WriteConstraint { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { let v = match *self { WriteConstraint::WriteAsRead(v) => new_element("writeAsRead", Some(format!("{}", v))), WriteConstraint::UseEnumeratedValues(v) => { @@ -79,9 +79,9 @@ impl Encode for WriteConstraint { impl Parse for WriteConstraintRange { type Object = WriteConstraintRange; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { Ok(WriteConstraintRange { min: tree.get_child_u32("minimum")?, max: tree.get_child_u32("maximum")?, @@ -91,9 +91,9 @@ impl Parse for WriteConstraintRange { #[cfg(feature = "unproven")] impl Encode for WriteConstraintRange { - type Error = SVDError; + type Error = anyhow::Error; - fn encode(&self) -> Result { + fn encode(&self) -> Result { Ok(Element { prefix: None, namespace: None, diff --git a/src/types.rs b/src/types.rs index c8ff23eb..e3288388 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,6 +1,5 @@ //! Shared primitive types for use in SVD objects. -use failure::ResultExt; use xmltree::Element; #[cfg(feature = "unproven")] @@ -9,7 +8,7 @@ pub use crate::parse::optional as parse_optional; pub use crate::parse::Parse; use crate::elementext::ElementExt; -use crate::error::{SVDError, SVDErrorKind}; +use crate::error::*; macro_rules! unwrap { ($e:expr) => { @@ -19,15 +18,13 @@ macro_rules! unwrap { impl Parse for u32 { type Object = u32; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result { + fn parse(tree: &Element) -> Result { let text = tree.get_text()?; if text.starts_with("0x") || text.starts_with("0X") { - u32::from_str_radix(&text["0x".len()..], 16) - .context(SVDErrorKind::Other(format!("{} invalid", text))) - .map_err(|e| e.into()) + u32::from_str_radix(&text["0x".len()..], 16).context(format!("{} invalid", text)) } else if text.starts_with('#') { // Handle strings in the binary form of: // #01101x1 @@ -36,19 +33,15 @@ impl Parse for u32 { &str::replace(&text.to_lowercase()["#".len()..], "x", "0"), 2, ) - .context(SVDErrorKind::Other(format!("{} invalid", text))) - .map_err(|e| e.into()) + .context(format!("{} invalid", text)) } else if text.starts_with("0b") { // Handle strings in the binary form of: // 0b01101x1 // along with don't care character x (replaced with 0) u32::from_str_radix(&str::replace(&text["0b".len()..], "x", "0"), 2) - .context(SVDErrorKind::Other(format!("{} invalid", text))) - .map_err(|e| e.into()) + .context(format!("{} invalid", text)) } else { - text.parse::() - .context(SVDErrorKind::Other(format!("{} invalid", text))) - .map_err(|e| e.into()) + text.parse::().context(format!("{} invalid", text)) } } } @@ -57,8 +50,9 @@ pub struct BoolParse; impl Parse for BoolParse { type Object = bool; - type Error = SVDError; - fn parse(tree: &Element) -> Result { + type Error = anyhow::Error; + + fn parse(tree: &Element) -> Result { let text = unwrap!(tree.text.as_ref()); Ok(match text.as_ref() { "0" => false, @@ -66,9 +60,7 @@ impl Parse for BoolParse { _ => match text.parse() { Ok(b) => b, Err(e) => { - return Err( - SVDErrorKind::InvalidBooleanValue(tree.clone(), text.clone(), e).into(), - ) + return Err(SVDError::InvalidBooleanValue(tree.clone(), text.clone(), e).into()) } }, }) @@ -79,9 +71,9 @@ pub struct DimIndex; impl Parse for DimIndex { type Object = Vec; - type Error = SVDError; + type Error = anyhow::Error; - fn parse(tree: &Element) -> Result, SVDError> { + fn parse(tree: &Element) -> Result> { let text = tree.get_text()?; if text.contains('-') { let mut parts = text.splitn(2, '-'); diff --git a/tests/bad_svd.rs b/tests/bad_svd.rs index b3843e65..a4137964 100644 --- a/tests/bad_svd.rs +++ b/tests/bad_svd.rs @@ -1,7 +1,5 @@ use svd_parser as svd; -use failure::Fail; - #[test] fn arm_sample_faulty() { let xml = include_str!(concat!( @@ -9,7 +7,7 @@ fn arm_sample_faulty() { "/tests/ARM_Sample_faulty.svd" )); if let Err(e) = svd::parse(xml) { - for e in Fail::iter_chain(&e) { + for e in e.chain() { println!("{}", e); } } else {