@@ -315,49 +315,58 @@ pub struct ActorError {
315315}
316316
317317/// The kinds of actor serving errors.
318- #[ derive( thiserror:: Error , Debug ) ]
318+ #[ derive( thiserror:: Error , Debug , Clone , Serialize , Deserialize , PartialEq , Eq ) ]
319319pub enum ActorErrorKind {
320+ /// Generic error with a formatted message.
321+ #[ error( "{0}" ) ]
322+ Generic ( String ) ,
323+
324+ /// An actor supervision event was not handled.
325+ #[ error( "supervision: {0}" ) ]
326+ UnhandledSupervisionEvent ( Box < ActorSupervisionEvent > ) ,
327+ }
328+
329+ impl ActorErrorKind {
320330 /// Error while processing actor, i.e., returned by the actor's
321331 /// processing method.
322- #[ error( "processing error: {0}" ) ]
323- Processing ( #[ source] anyhow:: Error ) ,
332+ pub fn processing ( err : anyhow:: Error ) -> Self {
333+ Self :: Generic ( format ! ( "processing error: {}" , err) )
334+ }
324335
325336 /// Unwound stracktrace of a panic.
326- #[ error( "panic: {0}" ) ]
327- Panic ( #[ source] anyhow:: Error ) ,
337+ pub fn panic ( err : anyhow:: Error ) -> Self {
338+ Self :: Generic ( format ! ( "panic: {}" , err) )
339+ }
328340
329341 /// Error during actor initialization.
330- #[ error( "initialization error: {0}" ) ]
331- Init ( #[ source] anyhow:: Error ) ,
342+ pub fn init ( err : anyhow:: Error ) -> Self {
343+ Self :: Generic ( format ! ( "initialization error: {}" , err) )
344+ }
332345
333346 /// An underlying mailbox error.
334- #[ error( transparent) ]
335- Mailbox ( #[ from] MailboxError ) ,
347+ pub fn mailbox ( err : MailboxError ) -> Self {
348+ Self :: Generic ( err. to_string ( ) )
349+ }
336350
337351 /// An underlying mailbox sender error.
338- #[ error( transparent) ]
339- MailboxSender ( #[ from] MailboxSenderError ) ,
352+ pub fn mailbox_sender ( err : MailboxSenderError ) -> Self {
353+ Self :: Generic ( err. to_string ( ) )
354+ }
340355
341356 /// An underlying checkpoint error.
342- #[ error( "checkpoint error: {0}" ) ]
343- Checkpoint ( #[ source] CheckpointError ) ,
357+ pub fn checkpoint ( err : CheckpointError ) -> Self {
358+ Self :: Generic ( format ! ( "checkpoint error: {}" , err) )
359+ }
344360
345361 /// An underlying message log error.
346- #[ error( "message log error: {0}" ) ]
347- MessageLog ( #[ source] MessageLogError ) ,
362+ pub fn message_log ( err : MessageLogError ) -> Self {
363+ Self :: Generic ( format ! ( "message log error: {}" , err) )
364+ }
348365
349366 /// The actor's state could not be determined.
350- #[ error( "actor is in an indeterminate state" ) ]
351- IndeterminateState ,
352-
353- /// An actor supervision event was not handled.
354- #[ error( "supervision: {0}" ) ]
355- UnhandledSupervisionEvent ( #[ from] ActorSupervisionEvent ) ,
356-
357- /// A special kind of error that allows us to clone errors: we can keep the
358- /// error string, but we lose the error structure.
359- #[ error( "{0}" ) ]
360- Passthrough ( #[ from] anyhow:: Error ) ,
367+ pub fn indeterminate_state ( ) -> Self {
368+ Self :: Generic ( "actor is in an indeterminate state" . to_string ( ) )
369+ }
361370}
362371
363372impl ActorError {
@@ -368,14 +377,6 @@ impl ActorError {
368377 kind : Box :: new ( kind) ,
369378 }
370379 }
371-
372- /// Passthrough this error.
373- fn passthrough ( & self ) -> Self {
374- ActorError :: new (
375- & self . actor_id ,
376- ActorErrorKind :: Passthrough ( anyhow:: anyhow!( "{}" , self . kind) ) ,
377- )
378- }
379380}
380381
381382impl fmt:: Display for ActorError {
@@ -395,7 +396,7 @@ impl From<MailboxError> for ActorError {
395396 fn from ( inner : MailboxError ) -> Self {
396397 Self {
397398 actor_id : Box :: new ( inner. actor_id ( ) . clone ( ) ) ,
398- kind : Box :: new ( ActorErrorKind :: from ( inner) ) ,
399+ kind : Box :: new ( ActorErrorKind :: mailbox ( inner) ) ,
399400 }
400401 }
401402}
@@ -404,7 +405,7 @@ impl From<MailboxSenderError> for ActorError {
404405 fn from ( inner : MailboxSenderError ) -> Self {
405406 Self {
406407 actor_id : Box :: new ( inner. location ( ) . actor_id ( ) . clone ( ) ) ,
407- kind : Box :: new ( ActorErrorKind :: from ( inner) ) ,
408+ kind : Box :: new ( ActorErrorKind :: mailbox_sender ( inner) ) ,
408409 }
409410 }
410411}
@@ -413,7 +414,7 @@ impl From<ActorSupervisionEvent> for ActorError {
413414 fn from ( inner : ActorSupervisionEvent ) -> Self {
414415 Self {
415416 actor_id : Box :: new ( inner. actor_id . clone ( ) ) ,
416- kind : Box :: new ( ActorErrorKind :: UnhandledSupervisionEvent ( inner) ) ,
417+ kind : Box :: new ( ActorErrorKind :: UnhandledSupervisionEvent ( Box :: new ( inner) ) ) ,
417418 }
418419 }
419420}
@@ -473,9 +474,8 @@ pub enum ActorStatus {
473474 Stopping ,
474475 /// The actor is stopped. It is no longer processing messages.
475476 Stopped ,
476- /// The actor failed with the provided actor error formatted in string
477- /// representation.
478- Failed ( String ) ,
477+ /// The actor failed with the provided actor error.
478+ Failed ( ActorErrorKind ) ,
479479}
480480
481481impl ActorStatus {
@@ -489,23 +489,11 @@ impl ActorStatus {
489489 matches ! ( self , Self :: Failed ( _) )
490490 }
491491
492- /// Create a passthrough of this status. The returned status is a clone,
493- /// except that [`ActorStatus::Failed`] is replaced with its passthrough.
494- fn passthrough ( & self ) -> Self {
495- match self {
496- Self :: Unknown => Self :: Unknown ,
497- Self :: Created => Self :: Created ,
498- Self :: Initializing => Self :: Initializing ,
499- Self :: Client => Self :: Client ,
500- Self :: Idle => Self :: Idle ,
501- Self :: Processing ( instant, handler) => Self :: Processing ( * instant, handler. clone ( ) ) ,
502- Self :: Saving ( instant) => Self :: Saving ( * instant) ,
503- Self :: Loading ( instant) => Self :: Loading ( * instant) ,
504- Self :: Stopping => Self :: Stopping ,
505- Self :: Stopped => Self :: Stopped ,
506- Self :: Failed ( err) => Self :: Failed ( err. clone ( ) ) ,
507- }
492+ /// Create a generic failure status with the provided error message.
493+ pub fn generic_failure ( message : impl Into < String > ) -> Self {
494+ Self :: Failed ( ActorErrorKind :: Generic ( message. into ( ) ) )
508495 }
496+
509497 fn span_string ( & self ) -> & ' static str {
510498 self . arm ( ) . unwrap_or_default ( )
511499 }
@@ -662,7 +650,7 @@ impl<A: Actor> IntoFuture for ActorHandle<A> {
662650 let result = status_receiver. wait_for ( ActorStatus :: is_terminal) . await ;
663651 match result {
664652 Err ( _) => ActorStatus :: Unknown ,
665- Ok ( status) => status. passthrough ( ) ,
653+ Ok ( status) => status. clone ( ) ,
666654 }
667655 } ;
668656
0 commit comments