Skip to content

Commit

Permalink
Report non-fatal errors for failed tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Sep 23, 2020
1 parent 8d87741 commit b036252
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public static Task<TResult> SafeContinueWithFromAsync<TResult>(
// This is the only place in the code where we're allowed to call ContinueWith.
var nextTask = task.ContinueWith(continuationFunction, cancellationToken, continuationOptions | TaskContinuationOptions.LazyCancellation, scheduler).Unwrap();

nextTask.ContinueWith(ReportFatalError, continuationFunction,
nextTask.ContinueWith(ReportNonFatalError, continuationFunction,
CancellationToken.None,
TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
Expand Down Expand Up @@ -412,7 +412,7 @@ public static Task SafeContinueWithFromAsync(
// the behavior we want.
// This is the only place in the code where we're allowed to call ContinueWith.
var nextTask = task.ContinueWith(continuationFunction, cancellationToken, continuationOptions | TaskContinuationOptions.LazyCancellation, scheduler).Unwrap();
ReportFatalError(nextTask, continuationFunction);
ReportNonFatalError(nextTask, continuationFunction);
return nextTask;
}

Expand Down Expand Up @@ -451,7 +451,7 @@ public static Task SafeContinueWithFromAsync<TInput>(
// the behavior we want.
// This is the only place in the code where we're allowed to call ContinueWith.
var nextTask = task.ContinueWith(continuationFunction, cancellationToken, continuationOptions | TaskContinuationOptions.LazyCancellation, scheduler).Unwrap();
ReportFatalError(nextTask, continuationFunction);
ReportNonFatalError(nextTask, continuationFunction);
return nextTask;
}

Expand Down Expand Up @@ -536,16 +536,16 @@ public static Task ContinueWithAfterDelayFromAsync(
cancellationToken, taskContinuationOptions, scheduler).Unwrap();
}

internal static void ReportFatalError(Task task, object continuationFunction)
internal static void ReportNonFatalError(Task task, object continuationFunction)
{
task.ContinueWith(ReportFatalErrorWorker, continuationFunction,
task.ContinueWith(ReportNonFatalErrorWorker, continuationFunction,
CancellationToken.None,
TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
}

[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
private static void ReportFatalErrorWorker(Task task, object continuationFunction)
private static void ReportNonFatalErrorWorker(Task task, object continuationFunction)
{
var exception = task.Exception;
var methodInfo = ((Delegate)continuationFunction).GetMethodInfo();
Expand All @@ -558,7 +558,7 @@ private static void ReportFatalErrorWorker(Task task, object continuationFunctio
// ...
// > ~67s // switch to thread 67
// > !dso // dump stack objects
FatalError.Report(exception);
FatalError.ReportWithoutCrash(exception);
}

public static Task ReportNonFatalErrorAsync(this Task task)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public static Task SafeStartNewFromAsync(this TaskFactory factory, Func<Task> ac
{
// The one and only place we can call StartNew<>().
var task = factory.StartNew(actionAsync, cancellationToken, TaskCreationOptions.None, scheduler).Unwrap();
TaskExtensions.ReportFatalError(task, actionAsync);
TaskExtensions.ReportNonFatalError(task, actionAsync);
return task;
}

public static Task<TResult> SafeStartNewFromAsync<TResult>(this TaskFactory factory, Func<Task<TResult>> funcAsync, CancellationToken cancellationToken, TaskScheduler scheduler)
{
// The one and only place we can call StartNew<>().
var task = factory.StartNew(funcAsync, cancellationToken, TaskCreationOptions.None, scheduler).Unwrap();
TaskExtensions.ReportFatalError(task, funcAsync);
TaskExtensions.ReportNonFatalError(task, funcAsync);
return task;
}
}
Expand Down

0 comments on commit b036252

Please sign in to comment.