mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-17 01:25:40 -05:00
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:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user