Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve status messages #5226

Merged
merged 8 commits into from
Sep 8, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,27 @@ private async Task<object> Initialize()
}
catch (Exception e)
{
return new Failure {Exception = e};
return new Status.Failure(e);
Aaronontheweb marked this conversation as resolved.
Show resolved Hide resolved
}
}

private bool WaitingForInitialization(object message) => message.Match()
.With<Initialized>(_ =>
{
UnbecomeStacked();
Stash.UnstashAll();
})
.With<Failure>(failure =>
private bool WaitingForInitialization(object message)
{
switch(message)
{
Log.Error(failure.Exception, "Error during snapshot store initialization");
Context.Stop(Self);
})
.Default(_ => Stash.Stash())
.WasHandled;
case Initialized _:
UnbecomeStacked();
Stash.UnstashAll();
return true;
case Status.Failure msg:
Log.Error(msg.Cause, "Error during snapshot store initialization");
Context.Stop(Self);
return true;
default:
Stash.Stash();
return true;
}
}

/// <summary>
/// TBD
Expand Down
10 changes: 8 additions & 2 deletions src/core/Akka.API.Tests/CoreAPISpec.ApproveCore.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -853,12 +853,14 @@ namespace Akka.Actor
}
public delegate void TransitionHandler<TState, TData>(TState initialState, TState nextState);
}
[System.ObsoleteAttribute("Use Akka.Actor.Status.Failure")]
public class Failure
{
public Failure() { }
public System.Exception Exception { get; set; }
public System.DateTime Timestamp { get; set; }
}
[System.ObsoleteAttribute("Use List of Akka.Actor.Status.Failure")]
public class Failures
{
public Failures() { }
Expand Down Expand Up @@ -1720,16 +1722,20 @@ namespace Akka.Actor
public abstract class Status
{
protected Status() { }
public class Failure : Akka.Actor.Status
public sealed class Failure : Akka.Actor.Status
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

{
public readonly System.Exception Cause;
public readonly object State;
public Failure(System.Exception cause) { }
public Failure(System.Exception cause, object state) { }
public override string ToString() { }
}
public class Success : Akka.Actor.Status
public sealed class Success : Akka.Actor.Status
{
public static readonly Akka.Actor.Status.Success Instance;
public readonly object Status;
public Success(object status) { }
public override string ToString() { }
}
}
public class StoppingSupervisorStrategy : Akka.Actor.SupervisorStrategyConfigurator
Expand Down
30 changes: 25 additions & 5 deletions src/core/Akka/Actor/ActorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public abstract class Status
/// <summary>
/// Indicates the success of some operation which has been performed
/// </summary>
public class Success : Status
public sealed class Success : Status
{
public static readonly Success Instance = new Success(null);

/// <summary>
/// TBD
/// </summary>
Expand All @@ -35,33 +37,51 @@ public Success(object status)
{
Status = status;
}

public override string ToString() => Status is null ? "Success" : $"Success: {Status}";
}

/// <summary>
/// Indicates the failure of some operation that was requested and includes an
/// <see cref="Exception"/> describing the underlying cause of the problem.
/// </summary>
public class Failure : Status
public sealed class Failure : Status
{
/// <summary>
/// The cause of the failure
/// </summary>
public readonly Exception Cause;

/// <summary>
/// The source state of the failure
/// It can be used to send the command message back
/// </summary>
public readonly object State;

/// <summary>
/// Initializes a new instance of the <see cref="Failure"/> class.
/// </summary>
/// <param name="cause">The cause of the failure</param>
public Failure(Exception cause)
{
Cause = cause;
State = null;
}

/// <inheritdoc/>
public override string ToString()
/// <summary>
/// Initializes a new instance of the <see cref="Failure"/> class.
/// </summary>
/// <param name="cause">The cause of the failure</param>
/// <param name="state">The source state of the failure</param>
public Failure(Exception cause, object state)
{
return $"Failure: {Cause}";
Cause = cause;
State = state;
}

/// <inheritdoc/>
public override string ToString()
=> State is null ? $"Failure: {Cause}" : $"Failure[{State}]: {Cause}";
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/Akka/Actor/SupervisorStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ public override int GetHashCode()
/// <summary>
/// Collection of failures, used to keep track of how many times a given actor has failed.
/// </summary>
[Obsolete("Use List of Akka.Actor.Status.Failure")]
public class Failures
{
/// <summary>
Expand All @@ -769,6 +770,7 @@ public Failures()
/// <summary>
/// Represents a single failure.
/// </summary>
[Obsolete("Use Akka.Actor.Status.Failure")]
public class Failure
{
/// <summary>
Expand Down