Skip to content

Commit

Permalink
refactored query execution failure callback to take exception (micros…
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Dresser authored Jun 14, 2017
1 parent 85dc0b9 commit 9b91a93
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private EditSession GetActiveSessionOrThrow(string ownerUri)
};

// Setup callback for failed query execution
Query.QueryAsyncEventHandler queryCompleteFailureCallback = q =>
Query.QueryAsyncErrorEventHandler queryCompleteFailureCallback = (q, e) =>
{
taskCompletion.SetResult(new EditSession.EditSessionQueryExecutionState(null));
return Task.FromResult(0);
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Query(string queryText, ConnectionInfo connection, QueryExecutionSettings
/// Delegate type for callback when a query connection fails
/// </summary>
/// <param name="message">Error message for the failing query</param>
public delegate Task QueryAsyncErrorEventHandler(string message);
public delegate Task QueryAsyncErrorEventHandler(Query q, Exception e);

/// <summary>
/// Callback for when the query has completed successfully
Expand All @@ -168,7 +168,7 @@ public Query(string queryText, ConnectionInfo connection, QueryExecutionSettings
/// <summary>
/// Callback for when the query has failed
/// </summary>
public event QueryAsyncEventHandler QueryFailed;
public event QueryAsyncErrorEventHandler QueryFailed;

/// <summary>
/// Event to be called when a resultset has completed.
Expand Down Expand Up @@ -395,12 +395,12 @@ private async Task ExecuteInternal()
await QueryCompleted(this);
}
}
catch (Exception)
catch (Exception e)
{
// Call the query failure callback
if (QueryFailed != null)
{
await QueryFailed(this);
await QueryFailed(this, e);
}
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public async Task InterServiceExecuteQuery(ExecuteRequestParamsBase executeParam
Func<Query, Task<bool>> queryCreateSuccessFunc,
Func<string, Task> queryCreateFailFunc,
Query.QueryAsyncEventHandler querySuccessFunc,
Query.QueryAsyncEventHandler queryFailureFunc)
Query.QueryAsyncErrorEventHandler queryFailureFunc)
{
Validate.IsNotNull(nameof(executeParams), executeParams);
Validate.IsNotNull(nameof(queryEventSender), queryEventSender);
Expand Down Expand Up @@ -478,7 +478,7 @@ private Query CreateQuery(ExecuteRequestParamsBase executeParams)
private static void ExecuteAndCompleteQuery(string ownerUri, Query query,
IEventSender eventSender,
Query.QueryAsyncEventHandler querySuccessCallback,
Query.QueryAsyncEventHandler queryFailureCallback)
Query.QueryAsyncErrorEventHandler queryFailureCallback)
{
// Setup the callback to send the complete event
Query.QueryAsyncEventHandler completeCallback = async q =>
Expand All @@ -492,8 +492,21 @@ private static void ExecuteAndCompleteQuery(string ownerUri, Query query,

await eventSender.SendEvent(QueryCompleteEvent.Type, eventParams);
};

// Setup the callback to send the complete event
Query.QueryAsyncErrorEventHandler failureCallback = async (q, e) =>
{
// Send back the results
QueryCompleteParams eventParams = new QueryCompleteParams
{
OwnerUri = ownerUri,
BatchSummaries = q.BatchSummaries
};

await eventSender.SendEvent(QueryCompleteEvent.Type, eventParams);
};
query.QueryCompleted += completeCallback;
query.QueryFailed += completeCallback;
query.QueryFailed += failureCallback;

// Add the callbacks that were provided by the caller
// If they're null, that's no problem
Expand Down

0 comments on commit 9b91a93

Please sign in to comment.