public async Task CanInvokeMethodThatReturnsCancelledTask() { RemoteInvocationException exception = await Assert.ThrowsAnyAsync <RemoteInvocationException>(() => this.clientRpc.InvokeAsync(nameof(Server.ServerMethodThatReturnsCancelledTask))); Assert.Null(exception.RemoteErrorCode); Assert.Null(exception.RemoteStackTrace); }
public void ShowError_WhenArgumentIsRemoteInvocationExceptionForSignatureException_ShowsError() { var remoteError = new RemoteError( typeName: typeof(SignatureException).FullName, new LogMessage(LogLevel.Error, message: "a", NuGetLogCode.NU3018), new[] { new LogMessage(LogLevel.Error, message: "b", NuGetLogCode.NU3019), new LogMessage(LogLevel.Warning, message: "c", NuGetLogCode.NU3027) }, projectContextLogMessage: "d", activityLogMessage: "e"); var exception = new RemoteInvocationException( message: "f", errorCode: 0, errorData: null, deserializedErrorData: remoteError); var defaultLogger = new Mock <INuGetUILogger>(); var projectLogger = new Mock <INuGetUILogger>(); defaultLogger.Setup(x => x.ReportError(It.Is <ILogMessage>(logMessage => ReferenceEquals(logMessage, remoteError.LogMessage)))); defaultLogger.Setup(x => x.ReportError(It.Is <ILogMessage>(logMessage => ReferenceEquals(logMessage, remoteError.LogMessages[0])))); defaultLogger.Setup(x => x.ReportError(It.Is <ILogMessage>(logMessage => ReferenceEquals(logMessage, remoteError.LogMessages[1])))); projectLogger.Setup(x => x.Log(It.Is <ILogMessage>(logMessage => ReferenceEquals(logMessage, remoteError.LogMessage)))); projectLogger.Setup(x => x.Log(It.Is <ILogMessage>(logMessage => ReferenceEquals(logMessage, remoteError.LogMessages[0])))); projectLogger.Setup(x => x.Log(It.Is <ILogMessage>(logMessage => ReferenceEquals(logMessage, remoteError.LogMessages[1])))); using (NuGetUI ui = CreateNuGetUI(defaultLogger.Object, projectLogger.Object)) { ui.ShowError(exception); defaultLogger.VerifyAll(); projectLogger.VerifyAll(); } }
public void ShowError_WhenArgumentIsRemoteInvocationExceptionForOtherException_ShowsError() { var remoteException = new ArgumentException(message: "a", new DivideByZeroException(message: "b")); var remoteError = RemoteErrorUtility.ToRemoteError(remoteException); var exception = new RemoteInvocationException( message: "c", errorCode: 0, errorData: null, deserializedErrorData: remoteError); var defaultLogger = new Mock <INuGetUILogger>(); var projectLogger = new Mock <INuGetUILogger>(); defaultLogger.Setup( x => x.ReportError( It.Is <ILogMessage>(logMessage => ReferenceEquals(logMessage, remoteError.LogMessage)))); projectLogger.Setup( x => x.Log( It.Is <MessageLevel>(level => level == MessageLevel.Error), It.Is <string>(message => message == remoteException.ToString()))); using (NuGetUI ui = CreateNuGetUI(defaultLogger.Object, projectLogger.Object)) { ui.ShowError(exception); defaultLogger.VerifyAll(); projectLogger.VerifyAll(); } }
public async Task CanPassExceptionFromServer() { const int COR_E_UNAUTHORIZEDACCESS = unchecked ((int)0x80070005); RemoteInvocationException exception = await Assert.ThrowsAnyAsync <RemoteInvocationException>(() => this.clientRpc.InvokeAsync(nameof(Server.MethodThatThrowsUnauthorizedAccessException))); Assert.NotNull(exception.RemoteStackTrace); Assert.StrictEqual(COR_E_UNAUTHORIZEDACCESS.ToString(CultureInfo.InvariantCulture), exception.RemoteErrorCode); }
public async Task CanPassExceptionFromServer() { #pragma warning disable SA1139 // Use literal suffix notation instead of casting const int COR_E_UNAUTHORIZEDACCESS = unchecked ((int)0x80070005); #pragma warning restore SA1139 // Use literal suffix notation instead of casting RemoteInvocationException exception = await Assert.ThrowsAnyAsync <RemoteInvocationException>(() => this.clientRpc.InvokeAsync(nameof(Server.MethodThatThrowsUnauthorizedAccessException))); Assert.NotNull(exception.RemoteStackTrace); Assert.StrictEqual(COR_E_UNAUTHORIZEDACCESS.ToString(CultureInfo.InvariantCulture), exception.RemoteErrorCode); }
public void TestRemoteInvocationExceptionNull() { var mockFault = new MockFault(); var exception = new RemoteInvocationException(message: null, errorCode: -1, errorData: null); mockFault.SetExtraParameters(exception, emptyCallstack: false); Assert.Equal(exception.GetParameterString(), mockFault.Map[7]); }
public void TestRemoteInvocationException() { var mockFault = new MockFault(); var exception = new RemoteInvocationException("test", errorCode: 100, "remoteErrorData"); mockFault.SetExtraParameters(exception, emptyCallstack: false); Assert.Equal(exception.GetParameterString(), mockFault.Map[7]); }
public void Ctor_Message_Code_Data() { var data = new CommonErrorData(); var ex = new RemoteInvocationException(SomeMessage, 123, data); Assert.Equal(SomeMessage, ex.Message); Assert.Equal(123, ex.ErrorCode); Assert.Same(data, ex.ErrorData); Assert.Null(ex.DeserializedErrorData); }
public void TestRemoteInvocationExceptionNull() { var mockFault = new MockFault(); var exception = new RemoteInvocationException(message: null, remoteStack: null, remoteCode: null); mockFault.SetExtraParameters(exception); Assert.Equal(exception.GetParameterString(), mockFault.Map[8]); }
public void TestRemoteInvocationException() { var mockFault = new MockFault(); var exception = new RemoteInvocationException("test", "remoteCallstack", "remoteErrorCode"); mockFault.SetExtraParameters(exception); Assert.Equal(exception.GetParameterString(), mockFault.Map[8]); }
public void Serializable() { var data = new CommonErrorData(); var deserializedData = new CommonErrorData(); var original = new RemoteInvocationException(SomeMessage, 123, data, deserializedData); var deserialized = BinaryFormatterRoundtrip(original); Assert.Equal(original.Message, deserialized.Message); Assert.Equal(original.ErrorCode, deserialized.ErrorCode); Assert.Null(deserialized.ErrorData); Assert.Null(deserialized.DeserializedErrorData); }
public async Task CanPassExceptionFromServer() { #pragma warning disable SA1139 // Use literal suffix notation instead of casting const int COR_E_UNAUTHORIZEDACCESS = unchecked ((int)0x80070005); #pragma warning restore SA1139 // Use literal suffix notation instead of casting RemoteInvocationException exception = await Assert.ThrowsAnyAsync <RemoteInvocationException>(() => this.clientRpc.InvokeAsync(nameof(Server.MethodThatThrowsUnauthorizedAccessException))); Assert.Equal((int)JsonRpcErrorCode.InvocationError, exception.ErrorCode); var errorData = ((JToken?)exception.ErrorData) !.ToObject <CommonErrorData>(); Assert.NotNull(errorData.StackTrace); Assert.StrictEqual(COR_E_UNAUTHORIZEDACCESS, errorData.HResult); }
private static string GetStackForRemoteException(RemoteInvocationException remoteException) { var text = GetStackForException(remoteException, includeMessageOnly: true); if (remoteException.ErrorData == null) { return(text); } text = $"{text}{Environment.NewLine}---> (Remote Exception) {remoteException.ErrorData.ToString()} <--- {Environment.NewLine}"; return(text); }
public async Task CanPassExceptionFromServer_ErrorData() { RemoteInvocationException exception = await Assert.ThrowsAnyAsync <RemoteInvocationException>(() => this.clientRpc.InvokeAsync(nameof(Server.MethodThatThrowsUnauthorizedAccessException))); Assert.Equal((int)JsonRpcErrorCode.InvocationError, exception.ErrorCode); var errorDataJToken = (JToken?)exception.ErrorData; Assert.NotNull(errorDataJToken); var errorData = errorDataJToken !.ToObject <CommonErrorData>(); Assert.NotNull(errorData.StackTrace); Assert.StrictEqual(COR_E_UNAUTHORIZEDACCESS, errorData.HResult); }
public async Task CanCallAsyncMethodThatThrows() { RemoteInvocationException exception = await Assert.ThrowsAnyAsync <RemoteInvocationException>(() => this.clientRpc.InvokeAsync <string>(nameof(Server.AsyncMethodThatThrows))); Assert.NotNull(exception.RemoteStackTrace); }
public static async Task <Stream> RequestServiceAsync( Workspace workspace, HubClient client, string serviceName, HostGroup hostGroup, TimeSpan timeout, CancellationToken cancellationToken) { const int max_retry = 10; const int retry_delayInMS = 50; RemoteInvocationException lastException = null; var descriptor = new ServiceDescriptor(serviceName) { HostGroup = hostGroup }; // call to get service can fail due to this bug - devdiv#288961 or more. // until root cause is fixed, we decide to have retry rather than fail right away for (var i = 0; i < max_retry; i++) { try { // we are wrapping HubClient.RequestServiceAsync since we can't control its internal timeout value ourselves. // we have bug opened to track the issue. // https://devdiv.visualstudio.com/DefaultCollection/DevDiv/Editor/_workitems?id=378757&fullScreen=false&_a=edit // retry on cancellation token since HubClient will throw its own cancellation token // when it couldn't connect to service hub service for some reasons // (ex, OOP process GC blocked and not responding to request) // // we have double re-try here. we have these 2 seperated since 2 retries are for different problems. // as noted by 2 different issues above at the start of each 2 different retries. // first retry most likely deal with real issue on servicehub, second retry (cancellation) is to deal with // by design servicehub behavior we don't want to use. return(await RetryRemoteCallAsync <OperationCanceledException, Stream>( workspace, () => client.RequestServiceAsync(descriptor, cancellationToken), timeout, cancellationToken).ConfigureAwait(false)); } catch (RemoteInvocationException ex) { // save info only if it failed with different issue than before. if (lastException?.Message != ex.Message) { // RequestServiceAsync should never fail unless service itself is actually broken. // So far, we catched multiple issues from this NFW. so we will keep this NFW. ex.ReportServiceHubNFW("RequestServiceAsync Failed"); lastException = ex; } } // wait for retry_delayInMS before next try await Task.Delay(retry_delayInMS, cancellationToken).ConfigureAwait(false); } // crash right away to get better dump. otherwise, we will get dump from async exception // which most likely lost all valuable data FatalError.ReportUnlessCanceled(lastException); GC.KeepAlive(lastException); // unreachable throw ExceptionUtilities.Unreachable; }