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

Inroduce OnActorMethodFailedAsync virtual method to simplify error logging #1014

Merged
merged 6 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions src/Dapr.Actors/Runtime/Actor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -101,10 +101,11 @@
await this.SaveStateAsync();
}

internal Task OnInvokeFailedAsync()
internal async Task OnActorMethodFailedInternalAsync(ActorMethodContext actorMethodContext, Exception e)
{
await this.OnActorMethodFailedAsync(actorMethodContext, e);

Check warning on line 106 in src/Dapr.Actors/Runtime/Actor.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Runtime/Actor.cs#L106

Added line #L106 was not covered by tests
// Exception has been thrown by user code, reset the state in state manager.
return this.ResetStateAsync();
await this.ResetStateAsync();

Check warning on line 108 in src/Dapr.Actors/Runtime/Actor.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Runtime/Actor.cs#L108

Added line #L108 was not covered by tests
}

internal Task ResetStateAsync()
Expand Down Expand Up @@ -190,6 +191,30 @@
return Task.CompletedTask;
}

/// <summary>
/// Override this method for performing any action when invoking actor method has thrown an exception.
/// This method is invoked by actor runtime when invoking actor method has thrown an exception.
/// </summary>
/// <param name="actorMethodContext">
/// An <see cref="ActorMethodContext"/> describing the method that was invoked by actor runtime prior to this method.
/// </param>
/// <param name="e">Exception thrown by either actor method or by OnPreActorMethodAsync/OnPostActorMethodAsync overriden methods.</param>
/// <returns>
/// Returns a <see cref="Task">Task</see> representing post-actor-method operation.
/// </returns>
/// /// <remarks>
/// This method is invoked by actor runtime prior to:
/// <list type="bullet">
/// <item><description>Invoking an actor interface method when a client request comes.</description></item>
/// <item><description>Invoking a method when a reminder fires.</description></item>
/// <item><description>Invoking a timer callback when timer fires.</description></item>
/// </list>
/// </remarks>
protected virtual Task OnActorMethodFailedAsync(ActorMethodContext actorMethodContext, Exception e)
{
return Task.CompletedTask;

Check warning on line 215 in src/Dapr.Actors/Runtime/Actor.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Runtime/Actor.cs#L215

Added line #L215 was not covered by tests
}

/// <summary>
/// Registers a reminder with the actor.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/Dapr.Actors/Runtime/ActorManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -355,9 +355,9 @@
// PostActivate will save the state, its not invoked when actorFunc invocation throws.
await actor.OnPostActorMethodAsyncInternal(actorMethodContext);
}
catch (Exception)
catch (Exception e)
{
await actor.OnInvokeFailedAsync();
await actor.OnActorMethodFailedInternalAsync(actorMethodContext, e);

Check warning on line 360 in src/Dapr.Actors/Runtime/ActorManager.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Runtime/ActorManager.cs#L360

Added line #L360 was not covered by tests
throw;
}
finally
Expand Down
Loading