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

Select tools path relative to the current devenv.exe #1012

Merged
merged 7 commits into from Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -95,7 +95,7 @@ public async Task TestInvokeAsync_ThrowsTaskCanceledExceptionWhenTokenCanceled()
{
powerShell.AddScript("Start-Sleep -Seconds 30");

await Assert.ThrowsExceptionAsync<TaskCanceledException>(
await Assert.ThrowsExceptionAsync<OperationCanceledException>(
() => powerShell.InvokeAsync(new CancellationTokenSource(16).Token));
}
}
Expand All @@ -108,7 +108,7 @@ public async Task TestInvokeAsync_StopsPowershellWhenTokenCanceled()
{
powerShell.AddScript("Start-Sleep -Seconds 30");

await Assert.ThrowsExceptionAsync<TaskCanceledException>(
await Assert.ThrowsExceptionAsync<OperationCanceledException>(
() => powerShell.InvokeAsync(new CancellationTokenSource(16).Token));

Assert.AreEqual(PSInvocationState.Stopped, powerShell.InvocationStateInfo.State);
Expand Down
Expand Up @@ -102,24 +102,22 @@ private static SecureString ConvertToSecureString(string input)
CancellationToken cancelToken = default(CancellationToken))
{
cancelToken.ThrowIfCancellationRequested();
Task<PSDataCollection<PSObject>> powershellTask = Task.Factory.FromAsync(
powerShell.BeginInvoke(),
powerShell.EndInvoke);
var cancelTaskSource = new TaskCompletionSource<PSDataCollection<PSObject>>();
cancelToken.Register(() => powerShell.BeginStop(state => cancelTaskSource.TrySetCanceled(), null));
if (cancelToken.IsCancellationRequested)
Task<PSDataCollection<PSObject>> powershellTask =
Task.Factory.FromAsync(powerShell.BeginInvoke(), powerShell.EndInvoke);
cancelToken.Register(powerShell.Stop);

PSDataCollection<PSObject> output;
try
{
powerShell.BeginStop(state => cancelTaskSource.TrySetCanceled(), null);
output = await powershellTask;
}

Task<PSDataCollection<PSObject>> cancelTask = cancelTaskSource.Task;
Task<PSDataCollection<PSObject>> completedTask = await Task.WhenAny(powershellTask, cancelTask);
// Prevent a race condition where powershell task faults with PipelineStoppedException before cancelTask is canceled.
if (completedTask == powershellTask && completedTask.IsFaulted && cancelToken.IsCancellationRequested)
catch (Exception e) when (cancelToken.IsCancellationRequested)
{
await cancelTask;
throw new OperationCanceledException("PowerShell operation canceled", e, cancelToken);
}
return await completedTask;
// PowerShell can sometimes complete without error if the cancellation happend quickly enough.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: happened

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cancelToken.ThrowIfCancellationRequested();
return output;
}
}
}
Expand Up @@ -66,20 +66,24 @@ public override async Task<IAttachDebuggerStep> OnStartAsync()
{
installed = await _installer.Install(CancelToken);
}
catch (ActionPreferenceStopException e)
catch (OperationCanceledException)
{
// Don't prompt for cancellation.
}
catch (RuntimeException e)
{
UserPromptUtils.Default.ErrorPrompt(
Resources.AttachDebuggerConnectionFailedMessage,
Resources.UiDefaultPromptTitle,
e.ErrorRecord.InvocationInfo.Line + Environment.NewLine + Environment.NewLine + e.ErrorRecord);
e.ErrorRecord.Exception?.Message ?? e.ErrorRecord.ToString(),
Resources.AttachDebuggerInstallerError,
e.ErrorRecord.InvocationInfo.Line);
}
catch (Exception ex) when (!ErrorHandlerUtils.IsCriticalException(ex))
{
Debug.WriteLine($"{ex}");
UserPromptUtils.Default.ErrorPrompt(
ex.Message,
Resources.AttachDebuggerInstallerError,
Resources.UiDefaultPromptTitle,
ex.Message);
ex.StackTrace);
}

if (installed)
Expand Down