11//! SVD Errors.
22//! This module defines error types and messages for SVD parsing and encoding
33
4- use core:: fmt:: { self , Display } ;
5- use failure:: { Backtrace , Context , Fail } ;
6- use xmltree:: { Element , ParseError } ;
4+ pub use anyhow:: { Context , Result } ;
5+ use xmltree:: Element ;
76
8- #[ derive( Debug ) ]
9- pub struct SVDError {
10- inner : Context < SVDErrorKind > ,
11- }
12-
13- // TODO: Expand and make more complex output possible.
14- // We can use the `Element` to output name (if available) and etc.
157#[ allow( clippy:: large_enum_variant) ]
16- #[ derive( Clone , Debug , PartialEq , Eq , Fail ) ]
17- pub enum SVDErrorKind {
18- #[ fail ( display = "Unknown endianness `{}`" , _0 ) ]
8+ #[ derive( Clone , Debug , PartialEq , Eq , thiserror :: Error ) ]
9+ pub enum SVDError {
10+ #[ error ( "Unknown endianness `{0 }`" ) ]
1911 UnknownEndian ( String ) ,
2012 // TODO: Needs context
2113 // TODO: Better name
22- #[ fail ( display = "Expected a <{}> tag, found none" , _1 ) ]
14+ #[ error ( "Expected a <{1 }> tag, found none" ) ]
2315 MissingTag ( Element , String ) ,
24- #[ fail ( display = "Expected content in <{}> tag, found none" , _1 ) ]
16+ #[ error ( "Expected content in <{1 }> tag, found none" ) ]
2517 EmptyTag ( Element , String ) ,
26- #[ fail ( display = "ParseError" ) ]
18+ #[ error ( "ParseError" ) ]
2719 ParseError ( Element ) ,
28- #[ fail ( display = "NameMismatch" ) ]
20+ #[ error ( "NameMismatch" ) ]
2921 NameMismatch ( Element ) ,
30- #[ fail ( display = "unknown access variant '{}' found" , _1 ) ]
22+ #[ error ( "unknown access variant '{1 }' found" ) ]
3123 UnknownAccessType ( Element , String ) ,
32- #[ fail ( display = "Bit range invalid, {:?}" , _1 ) ]
24+ #[ error ( "Bit range invalid, {1 :?}" ) ]
3325 InvalidBitRange ( Element , InvalidBitRange ) ,
34- #[ fail ( display = "Unknown write constraint" ) ]
26+ #[ error ( "Unknown write constraint" ) ]
3527 UnknownWriteConstraint ( Element ) ,
36- #[ fail ( display = "Multiple wc found" ) ]
28+ #[ error ( "Multiple wc found" ) ]
3729 MoreThanOneWriteConstraint ( Element ) ,
38- #[ fail ( display = "Unknown usage variant" ) ]
30+ #[ error ( "Unknown usage variant" ) ]
3931 UnknownUsageVariant ( Element ) ,
40- #[ fail ( display = "Expected a <{}>, found ..." , _1 ) ]
32+ #[ error ( "Expected a <{1 }>, found ..." ) ]
4133 NotExpectedTag ( Element , String ) ,
42- #[ fail(
43- display = "Invalid RegisterCluster (expected register or cluster), found {}" ,
44- _1
45- ) ]
34+ #[ error( "Invalid RegisterCluster (expected register or cluster), found {1}" ) ]
4635 InvalidRegisterCluster ( Element , String ) ,
47- #[ fail ( display = "Invalid modifiedWriteValues variant, found {}" , _1 ) ]
36+ #[ error ( "Invalid modifiedWriteValues variant, found {1}" ) ]
4837 InvalidModifiedWriteValues ( Element , String ) ,
49- #[ fail(
50- display = "The content of the element could not be parsed to a boolean value {}: {}" ,
51- _1, _2
52- ) ]
38+ #[ error( "The content of the element could not be parsed to a boolean value {1}: {2}" ) ]
5339 InvalidBooleanValue ( Element , String , core:: str:: ParseBoolError ) ,
54- #[ fail ( display = "encoding method not implemented for svd object {}" , _0 ) ]
40+ #[ error ( "encoding method not implemented for svd object {0}" ) ]
5541 EncodeNotImplemented ( String ) ,
56- #[ fail ( display = "Error parsing SVD XML" ) ]
42+ #[ error ( "Error parsing SVD XML" ) ]
5743 FileParseError ,
58- // FIXME: Should not be used, only for prototyping
59- #[ fail( display = "{}" , _0) ]
60- Other ( String ) ,
6144}
6245
6346// TODO: Consider making into an Error
@@ -67,47 +50,3 @@ pub enum InvalidBitRange {
6750 ParseError ,
6851 MsbLsb ,
6952}
70-
71- impl Fail for SVDError {
72- fn cause ( & self ) -> Option < & dyn Fail > {
73- self . inner . cause ( )
74- }
75-
76- fn backtrace ( & self ) -> Option < & Backtrace > {
77- self . inner . backtrace ( )
78- }
79- }
80-
81- impl Display for SVDError {
82- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
83- Display :: fmt ( & self . inner , f)
84- }
85- }
86-
87- impl SVDError {
88- pub fn kind ( & self ) -> SVDErrorKind {
89- self . inner . get_context ( ) . clone ( )
90- }
91- }
92-
93- impl From < SVDErrorKind > for SVDError {
94- fn from ( kind : SVDErrorKind ) -> SVDError {
95- SVDError {
96- inner : Context :: new ( kind) ,
97- }
98- }
99- }
100-
101- impl From < Context < SVDErrorKind > > for SVDError {
102- fn from ( inner : Context < SVDErrorKind > ) -> SVDError {
103- SVDError { inner }
104- }
105- }
106-
107- impl From < ParseError > for SVDError {
108- fn from ( e : ParseError ) -> SVDError {
109- SVDError {
110- inner : e. context ( SVDErrorKind :: FileParseError ) ,
111- }
112- }
113- }
0 commit comments