提交 adb98a2d 编写于 作者: H Heejae Chang

add try catch at the first await so that we can get dump at right exception...

add try catch at the first await so that we can get dump at right exception point rather than having it as inner exception
上级 b73c499f
......@@ -8,6 +8,7 @@
using System.Threading.Tasks;
using StreamJsonRpc;
using Roslyn.Utilities;
using Microsoft.CodeAnalysis.ErrorReporting;
namespace Microsoft.CodeAnalysis.Remote
{
......@@ -38,23 +39,11 @@ internal static partial class Extensions
await task.ConfigureAwait(false);
}
}
catch (ObjectDisposedException)
catch (Exception ex) when (IsCancelled(ex))
{
// object disposed exception can be thrown from StreamJsonRpc if JsonRpc is disposed in the middle of read/write.
// the way we added cancellation support to the JsonRpc which doesn't support cancellation natively
// can cause this exception to happen. newer version supports cancellation token natively, but
// we can't use it now, so we will catch object disposed exception and check cancellation token
cancellationToken.ThrowIfCancellationRequested();
throw;
}
catch (OperationCanceledException)
{
// if cancelled due to us, throw cancellation exception.
cancellationToken.ThrowIfCancellationRequested();
// if canclled due to invocation is failed, rethrow merged cancellation
throw;
}
}
public static async Task<T> InvokeAsync<T>(
......@@ -84,23 +73,11 @@ internal static partial class Extensions
return result;
}
}
catch (ObjectDisposedException)
catch (Exception ex) when (IsCancelled(ex))
{
// object disposed exception can be thrown from StreamJsonRpc if JsonRpc is disposed in the middle of read/write.
// the way we added cancellation support to the JsonRpc which doesn't support cancellation natively
// can cause this exception to happen. newer version supports cancellation token natively, but
// we can't use it now, so we will catch object disposed exception and check cancellation token
cancellationToken.ThrowIfCancellationRequested();
throw;
}
catch (OperationCanceledException)
{
// if cancelled due to us, throw cancellation exception.
cancellationToken.ThrowIfCancellationRequested();
// if canclled due to invocation is failed, rethrow merged cancellation
throw;
}
}
public static async Task InvokeAsync(
......@@ -128,21 +105,9 @@ internal static partial class Extensions
await task.ConfigureAwait(false);
}
}
catch (ObjectDisposedException)
{
// object disposed exception can be thrown from StreamJsonRpc if JsonRpc is disposed in the middle of read/write.
// the way we added cancellation support to the JsonRpc which doesn't support cancellation natively
// can cause this exception to happen. newer version supports cancellation token natively, but
// we can't use it now, so we will catch object disposed exception and check cancellation token
cancellationToken.ThrowIfCancellationRequested();
throw;
}
catch (OperationCanceledException)
catch (Exception ex) when (IsCancelled(ex))
{
// if cancelled due to us, throw cancellation exception.
cancellationToken.ThrowIfCancellationRequested();
// if canclled due to invocation is failed, rethrow merged cancellation
throw;
}
}
......@@ -174,23 +139,25 @@ internal static partial class Extensions
return result;
}
}
catch (ObjectDisposedException)
catch (Exception ex) when (IsCancelled(ex))
{
// object disposed exception can be thrown from StreamJsonRpc if JsonRpc is disposed in the middle of read/write.
// the way we added cancellation support to the JsonRpc which doesn't support cancellation natively
// can cause this exception to happen. newer version supports cancellation token natively, but
// we can't use it now, so we will catch object disposed exception and check cancellation token
cancellationToken.ThrowIfCancellationRequested();
throw;
}
catch (OperationCanceledException)
{
// if cancelled due to us, throw cancellation exception.
cancellationToken.ThrowIfCancellationRequested();
}
// if canclled due to invocation is failed, rethrow merged cancellation
throw;
private static bool IsCancelled(Exception ex)
{
// object disposed exception can be thrown from StreamJsonRpc if JsonRpc is disposed in the middle of read/write.
// the way we added cancellation support to the JsonRpc which doesn't support cancellation natively
// can cause this exception to happen. newer version supports cancellation token natively, but
// we can't use it now, so we will catch object disposed exception and check cancellation token
if (ex is ObjectDisposedException || ex is OperationCanceledException)
{
return true;
}
return FatalError.Report(ex);
}
private static void RaiseCancellationIfInvokeFailed(Task task, CancellationTokenSource mergedCancellation, CancellationToken cancellationToken)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册