Exemple #1
0
 public int BeginExecute()
 {
     _cancelSource = new CancellationTokenSource();
     SafeErrorUtil.SafelyLogErrorAndForget(ExecuteAsync,
                                           "Error processing async evaluate request");
     return(VSConstants.S_OK);
 }
Exemple #2
0
        void LoadSymbolsCustomCommand(string guid, int id, object customIn, object customOut,
                                      ref bool cancelDefault)
        {
            if (guid != _loadSymbolsGuid || id != _loadSymbolsFromModuleId)
            {
                return;
            }

            try
            {
                _taskContext.ThrowIfNotOnMainThread();

                _programs.ForEach(LoadSymbols);
                RefreshSymbolsLoadingStatus();
            }
            catch (Exception e)
            {
                // Users will see that module is not loaded via Modules window,
                // thus not showing any extra messages.
                Trace.WriteLine($"Error while loading symbols: {e}");

                if (_vsiService.DebuggerOptions[DebuggerOption.EXCEPTION_METRICS] ==
                    DebuggerOptionState.ENABLED)
                {
                    SafeErrorUtil.SafelyLogError(() => {
                        _exceptionRecorder.Record(MethodBase.GetCurrentMethod(), e);
                    }, "Failed to record exception");
                }
            }

            // Do not invoke the handler for the command.
            cancelDefault = true;
        }
Exemple #3
0
 public async Task SafelyHandleErrorAsync_CallsHandlerOnAsyncErrorAsync()
 {
     await SafeErrorUtil.SafelyHandleErrorAsync(async () => {
         await Task.Yield();
         throw new TestException();
     }, handler);
     handler.Received().Invoke(Arg.Is<Exception>(e => e is TestException));
 }
Exemple #4
0
 public async Task SafelyLogErrorAsync()
 {
     await SafeErrorUtil.SafelyLogErrorAsync(async () =>
     {
         await Task.Yield();
         throw new TestException();
     }, "message");
     Assert.That(logSpy.GetOutput(), Contains.Substring("message"));
     Assert.That(logSpy.GetOutput(), Contains.Substring("TestException"));
 }
Exemple #5
0
        public async Task SafelyHandleErrorAsync_CallsHandlerOnSynchronousErrorAsync()
        {
            // Use a delegate to bypass warning that we don't use await.
            Func<Task> throwSynchronously = delegate
            {
                throw new TestException();
            };

            await SafeErrorUtil.SafelyHandleErrorAsync(throwSynchronously, handler);
            handler.Received().Invoke(Arg.Is<Exception>(e => e is TestException));
        }
Exemple #6
0
        public int EvaluateAsync(enum_EVALFLAGS flags, IDebugEventCallback2 callback)
        {
            Func <Task> evaluationTask = () => taskExecutor.SubmitAsync(async() =>
            {
                EvaluationResult evalResult = await asyncEvaluator.EvaluateExpressionAsync();
                debugEngineHandler.OnEvaluationComplete(Self, evalResult.Result, program, thread);
            }, CancellationToken.None, nameof(EvaluateAsync), typeof(DebugExpression));

            SafeErrorUtil.SafelyLogErrorAndForget(evaluationTask,
                                                  "EvaluateAsync: error evaluating expression asynchronously");

            return(VSConstants.S_OK);
        }
Exemple #7
0
 public void Intercept(IInvocation invocation)
 {
     try
     {
         invocation.Proceed();
     }
     catch (Exception ex)
     {
         SafeErrorUtil.SafelyLogError(() => {
             exceptionRecorder.Record(invocation.MethodInvocationTarget, ex);
         }, "Failed to record exception");
         throw;
     }
 }
        /// <summary>
        /// Records an exception using the caller of this method as the callsite.
        /// Does not throw exceptions.
        /// </summary>
        public static void SafelyRecordHere(this IExceptionRecorder recorder, Exception ex)
        {
            StackTrace stackTrace;

            try
            {
                // Create stack trace that skips the current frame.
                stackTrace = new StackTrace(1);
            }
            catch (Exception e)
            {
                Trace.WriteLine("Unable to capture stack trace: " + e.ToString());
                return;
            }

            SafeErrorUtil.SafelyLogError(() => Record(recorder, ex, stackTrace),
                                         "Recording exception");
        }
Exemple #9
0
        void RecordErrors(Action action)
        {
            try
            {
                action?.Invoke();
            }
            catch (Exception e)
            {
                Trace.WriteLine($"Error processing NoSourceWindow: {e}");

                if (_vsiService.DebuggerOptions[DebuggerOption.EXCEPTION_METRICS] ==
                    DebuggerOptionState.ENABLED)
                {
                    SafeErrorUtil.SafelyLogError(
                        () => { _exceptionRecorder.Record(MethodBase.GetCurrentMethod(), e); },
                        "Failed to record exception");
                }
            }
        }
Exemple #10
0
        public void Intercept(IInvocation invocation)
        {
            long initialTimestampInMicro =
                _timeSource.GetTimestampUs() - _debugSessionStartTimestampUs;

            try
            {
                invocation.Proceed();
            }
            finally
            {
                SafeErrorUtil.SafelyLogError(() =>
                {
                    long finalTimestampInMicro =
                        _timeSource.GetTimestampUs() - _debugSessionStartTimestampUs;
                    _methodInvocationRecorder.Record(invocation.MethodInvocationTarget,
                                                     initialTimestampInMicro,
                                                     finalTimestampInMicro);
                }, "Failed to record method invocation");
            }
        }
Exemple #11
0
 public void SafelyHandleError_HandlerThrows()
 {
     handler.When(x => x.Invoke(Arg.Any<Exception>())).Throw<HandlerException>();
     SafeErrorUtil.SafelyHandleError(() => { throw new TestException(); }, handler);
 }
Exemple #12
0
 public void SafelyHandleError_CallsHandlerOnError()
 {
     SafeErrorUtil.SafelyHandleError(() => { throw new TestException(); }, handler);
     handler.Received().Invoke(Arg.Is<Exception>(e => e is TestException));
 }
Exemple #13
0
 public void SafelyHandleError_DoesNotCallHandlerOnSuccess()
 {
     SafeErrorUtil.SafelyHandleError(() => { }, handler);
     handler.DidNotReceiveWithAnyArgs().Invoke(null);
 }
Exemple #14
0
 public async Task SafelyHandleErrorAsync_HandlerThrowsAsync()
 {
     handler.When(x => x.Invoke(Arg.Any<Exception>())).Throw<HandlerException>();
     await SafeErrorUtil.SafelyHandleErrorAsync(
         () => Task.FromException(new TestException()), handler);
 }
Exemple #15
0
 public async Task SafelyHandleErrorAsync_DoesNotCallHandlerOnSuccessAsync()
 {
     await SafeErrorUtil.SafelyHandleErrorAsync(() => Task.CompletedTask, handler);
     handler.DidNotReceiveWithAnyArgs().Invoke(null);
 }
Exemple #16
0
 public void SafelyLogError()
 {
     SafeErrorUtil.SafelyLogError(() => { throw new TestException(); }, "message");
     Assert.That(logSpy.GetOutput(), Contains.Substring("message"));
     Assert.That(logSpy.GetOutput(), Contains.Substring("TestException"));
 }