Query Execution: Better exception handling on unawaited async tasks (#502)

* WIP

* This code makes it work!

* Adding similar exception hanling behavior to saving result sets

* Adding unit tests for new extension methods
Auto-cleanup of proj file whitespace

* Implementing changes as per code review comments
This commit is contained in:
Benjamin Russell
2017-10-18 12:52:45 -07:00
committed by GitHub
parent 8db19d4b61
commit 705a89624a
5 changed files with 202 additions and 78 deletions

View File

@@ -504,9 +504,15 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
}
}
});
// Add exception handling to the save task
Task taskWithHandling = saveAsTask.ContinueWithOnFaulted(t =>
{
failureHandler?.Invoke(saveParams, t.Exception.Message).Wait();
});
// If saving the task fails, return a failure
if (!SaveTasks.TryAdd(saveParams.FilePath, saveAsTask))
if (!SaveTasks.TryAdd(saveParams.FilePath, taskWithHandling))
{
throw new InvalidOperationException(SR.QueryServiceSaveAsMiscStartingError);
}
@@ -537,7 +543,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
if (!SaveTasks.IsEmpty)
{
// Wait for tasks to finish before disposing ResultSet
Task.WhenAll(SaveTasks.Values.ToArray()).ContinueWith((antecedent) =>
Task.WhenAll(SaveTasks.Values.ToArray()).ContinueWith(antecedent =>
{
if (disposing)
{