@@ -10,7 +10,7 @@ use std::{
10
10
net:: SocketAddr ,
11
11
} ;
12
12
13
- use prost:: { DecodeError , Message } ;
13
+ use prost:: { Message , UnknownEnumValue } ;
14
14
15
15
use crate :: {
16
16
certificate:: { calculate_fingerprint, CertificateError , Fingerprint } ,
@@ -44,8 +44,8 @@ pub enum StateError {
44
44
NotFound { kind : ObjectKind , id : String } ,
45
45
#[ error( "{kind:?} '{id}' already exists" ) ]
46
46
Exists { kind : ObjectKind , id : String } ,
47
- #[ error( "Wrong request : {0}" ) ]
48
- WrongRequest ( String ) ,
47
+ #[ error( "Wrong field value : {0}" ) ]
48
+ WrongFieldValue ( UnknownEnumValue ) ,
49
49
#[ error( "Could not add certificate: {0}" ) ]
50
50
AddCertificate ( CertificateError ) ,
51
51
#[ error( "Could not remove certificate: {0}" ) ]
@@ -60,12 +60,6 @@ pub enum StateError {
60
60
FileError ( std:: io:: Error ) ,
61
61
}
62
62
63
- impl From < DecodeError > for StateError {
64
- fn from ( decode_error : DecodeError ) -> Self {
65
- Self :: WrongRequest ( format ! ( "Wrong field value: {decode_error}" ) )
66
- }
67
- }
68
-
69
63
/// The `ConfigState` represents the state of Sōzu's business, which is to forward traffic
70
64
/// from frontends to backends. Hence, it contains all details about:
71
65
///
@@ -223,7 +217,7 @@ impl ConfigState {
223
217
}
224
218
225
219
fn remove_listener ( & mut self , remove : & RemoveListener ) -> Result < ( ) , StateError > {
226
- match ListenerType :: try_from ( remove. proxy ) ? {
220
+ match ListenerType :: try_from ( remove. proxy ) . map_err ( StateError :: WrongFieldValue ) ? {
227
221
ListenerType :: Http => self . remove_http_listener ( & remove. address . clone ( ) . into ( ) ) ,
228
222
ListenerType :: Https => self . remove_https_listener ( & remove. address . clone ( ) . into ( ) ) ,
229
223
ListenerType :: Tcp => self . remove_tcp_listener ( & remove. address . clone ( ) . into ( ) ) ,
@@ -252,7 +246,7 @@ impl ConfigState {
252
246
}
253
247
254
248
fn activate_listener ( & mut self , activate : & ActivateListener ) -> Result < ( ) , StateError > {
255
- match ListenerType :: try_from ( activate. proxy ) ? {
249
+ match ListenerType :: try_from ( activate. proxy ) . map_err ( StateError :: WrongFieldValue ) ? {
256
250
ListenerType :: Http => self
257
251
. http_listeners
258
252
. get_mut ( & activate. address . clone ( ) . into ( ) )
@@ -281,7 +275,7 @@ impl ConfigState {
281
275
}
282
276
283
277
fn deactivate_listener ( & mut self , deactivate : & DeactivateListener ) -> Result < ( ) , StateError > {
284
- match ListenerType :: try_from ( deactivate. proxy ) ? {
278
+ match ListenerType :: try_from ( deactivate. proxy ) . map_err ( StateError :: WrongFieldValue ) ? {
285
279
ListenerType :: Http => self
286
280
. http_listeners
287
281
. get_mut ( & deactivate. address . clone ( ) . into ( ) )
0 commit comments