@@ -267,7 +267,7 @@ pub trait SpComponentUpdateHelper {
267267 log : & ' a slog:: Logger ,
268268 mgs_clients : & ' a mut MgsClients ,
269269 update : & ' a PendingMgsUpdate ,
270- ) -> BoxFuture < ' a , Result < ( ) , GatewayClientError > > ;
270+ ) -> BoxFuture < ' a , Result < ( ) , PostUpdateError > > ;
271271}
272272
273273/// Describes the live state of the component before the update begins
@@ -319,12 +319,66 @@ pub enum PrecheckError {
319319 WrongInactiveVersion { expected : ExpectedVersion , found : FoundVersion } ,
320320}
321321
322- #[ derive( Debug ) ]
322+ #[ derive( Debug , thiserror:: Error ) ]
323+ pub enum PostUpdateError {
324+ #[ error( "communicating with MGS" ) ]
325+ GatewayClientError ( #[ from] GatewayClientError ) ,
326+
327+ #[ error( "transient error: {message:?}" ) ]
328+ TransientError { message : String } ,
329+
330+ #[ error( "fatal error: {error:?}" ) ]
331+ FatalError { error : String } ,
332+ }
333+
334+ impl PostUpdateError {
335+ pub fn is_fatal ( & self ) -> bool {
336+ match self {
337+ PostUpdateError :: GatewayClientError ( error) => {
338+ !matches ! ( error, gateway_client:: Error :: CommunicationError ( _) )
339+ }
340+ PostUpdateError :: TransientError { .. } => false ,
341+ PostUpdateError :: FatalError { .. } => true ,
342+ }
343+ }
344+ }
345+
346+ #[ derive( Debug , Clone ) ]
323347pub enum FoundVersion {
324348 MissingVersion ,
325349 Version ( String ) ,
326350}
327351
352+ impl FoundVersion {
353+ pub fn matches (
354+ & self ,
355+ expected : & ExpectedVersion ,
356+ ) -> Result < ( ) , PrecheckError > {
357+ match ( expected, & self ) {
358+ // expected garbage, found garbage
359+ ( ExpectedVersion :: NoValidVersion , FoundVersion :: MissingVersion ) => {
360+ ( )
361+ }
362+ // expected a specific version and found it
363+ (
364+ ExpectedVersion :: Version ( artifact_version) ,
365+ FoundVersion :: Version ( found_version) ,
366+ ) if artifact_version. to_string ( ) == * found_version => ( ) ,
367+ // anything else is a mismatch
368+ ( ExpectedVersion :: NoValidVersion , FoundVersion :: Version ( _) )
369+ | ( ExpectedVersion :: Version ( _) , FoundVersion :: MissingVersion )
370+ | ( ExpectedVersion :: Version ( _) , FoundVersion :: Version ( _) ) => {
371+ return Err ( PrecheckError :: WrongInactiveVersion {
372+ expected : expected. clone ( ) ,
373+ found : self . clone ( ) ,
374+ } ) ;
375+ }
376+ } ;
377+
378+ Ok ( ( ) )
379+ }
380+ }
381+
328382pub ( crate ) fn error_means_caboose_is_invalid (
329383 error : & GatewayClientError ,
330384) -> bool {
0 commit comments