2020
2121use crate :: interface:: error:: InterfaceError ;
2222use crate :: interface:: mapping:: path:: MappingError ;
23- use crate :: interface:: { Aggregation , InterfaceTypeDef } ;
23+ use crate :: interface:: { Aggregation , InterfaceTypeDef , Ownership } ;
2424use crate :: introspection:: AddInterfaceError ;
2525use crate :: properties:: PropertiesError ;
2626use crate :: retention:: RetentionError ;
@@ -49,14 +49,6 @@ pub enum Error {
4949 /// Error while operating on the device introspection.
5050 #[ error( "couldn't complete introspection operation" ) ]
5151 AddInterface ( #[ from] AddInterfaceError ) ,
52- /// Invalid interface type when sending or receiving.
53- #[ error( "invalid interface type, expected {exp} but got {got}" ) ]
54- InterfaceType {
55- /// Expected interface type.
56- exp : InterfaceTypeDef ,
57- /// Actual interface type.
58- got : InterfaceTypeDef ,
59- } ,
6052 /// Couldn't find an interface with the given name.
6153 #[ error( "couldn't find interface '{name}'" ) ]
6254 InterfaceNotFound {
@@ -88,7 +80,7 @@ pub enum Error {
8880 Validation ( #[ from] UserValidationError ) ,
8981 /// Invalid aggregation between the interface and the data.
9082 #[ error( transparent) ]
91- Aggregation ( #[ from] AggregateError ) ,
83+ Aggregation ( #[ from] AggregationError ) ,
9284 /// Infallible conversion.
9385 #[ error( transparent) ]
9486 Infallible ( #[ from] Infallible ) ,
@@ -110,88 +102,78 @@ pub enum Error {
110102 Grpc ( #[ from] crate :: transport:: grpc:: GrpcError ) ,
111103}
112104
113- /// Aggregate error variant .
105+ /// Aggregation error.
114106///
115107/// This provides additional context in case of an aggregation error
116108#[ derive( Debug , thiserror:: Error ) ]
117- #[ error( "invalid aggregation in {ctx} for {interface}{path}, expected {exp} but got {got}" ) ]
109+ #[ error( "invalid aggregation for {interface}{path}, expected {exp} but got {got}" ) ]
118110#[ non_exhaustive]
119- pub struct AggregateError {
111+ pub struct AggregationError {
120112 /// Interface name
121113 interface : String ,
122114 /// Path
123115 path : String ,
124- /// Context to differentiate interface from payload error
125- ctx : AggregationCtx ,
126116 /// Expected aggregation of the interface.
127117 exp : Aggregation ,
128118 /// The actual aggregation.
129119 got : Aggregation ,
130120}
131121
132- impl AggregateError {
133- pub ( crate ) fn new (
134- interface : String ,
135- path : String ,
136- ctx : AggregationCtx ,
137- exp : Aggregation ,
138- got : Aggregation ,
139- ) -> Self {
122+ impl AggregationError {
123+ pub ( crate ) fn new ( interface : String , path : String , exp : Aggregation , got : Aggregation ) -> Self {
140124 Self {
141125 interface,
142126 path,
143- ctx,
144127 exp,
145128 got,
146129 }
147130 }
131+ }
148132
149- pub ( crate ) fn for_interface (
150- interface : impl Into < String > ,
151- path : impl Into < String > ,
152- exp : Aggregation ,
153- got : Aggregation ,
154- ) -> Self {
155- Self :: new (
156- interface. into ( ) ,
157- path. into ( ) ,
158- AggregationCtx :: Interface ,
159- exp,
160- got,
161- )
162- }
133+ /// Invalid interface type when sending or receiving.
134+ #[ derive( Debug , thiserror:: Error ) ]
135+ #[ error( "invalid interface type for {name}, expected {exp} but got {got}" ) ]
136+ pub struct InterfaceTypeError {
137+ /// Name of the interface.
138+ name : String ,
139+ /// Expected interface type.
140+ exp : InterfaceTypeDef ,
141+ /// Actual interface type.
142+ got : InterfaceTypeDef ,
143+ }
163144
164- #[ cfg( feature = "message-hub" ) ]
165- pub ( crate ) fn for_payload (
166- interface : impl Into < String > ,
167- path : impl Into < String > ,
168- exp : Aggregation ,
169- got : Aggregation ,
145+ impl InterfaceTypeError {
146+ pub ( crate ) fn new (
147+ name : impl Into < String > ,
148+ exp : InterfaceTypeDef ,
149+ got : InterfaceTypeDef ,
170150 ) -> Self {
171- Self :: new (
172- interface. into ( ) ,
173- path. into ( ) ,
174- AggregationCtx :: Payload ,
151+ Self {
152+ name : name. into ( ) ,
175153 exp,
176154 got,
177- )
155+ }
178156 }
179157}
180158
181- /// Context for the [AggregateError] error variant.
182- #[ derive( Debug , Clone ) ]
183- pub enum AggregationCtx {
184- /// Error occurring when checking the interface.
185- Interface ,
186- /// Error occurring when checking the payload data.
187- Payload ,
159+ /// Sending data on an interface not owned by the device
160+ #[ derive( Debug , thiserror:: Error ) ]
161+ #[ error( "invalid ownership for interface {name}, expected {exp} but got {got}" ) ]
162+ pub struct OwnershipError {
163+ /// Name of the interface.
164+ name : String ,
165+ /// Expected interface ownership.
166+ exp : Ownership ,
167+ /// Actual interface ownership.
168+ got : Ownership ,
188169}
189170
190- impl Display for AggregationCtx {
191- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
192- match self {
193- AggregationCtx :: Interface => write ! ( f, "interface" ) ,
194- AggregationCtx :: Payload => write ! ( f, "payload" ) ,
171+ impl OwnershipError {
172+ pub ( crate ) fn new ( name : impl Into < String > , exp : Ownership , got : Ownership ) -> Self {
173+ Self {
174+ name : name. into ( ) ,
175+ exp,
176+ got,
195177 }
196178 }
197179}
0 commit comments