public void CreateExceptionEvent() {
            // Arrange
            JObject message = JObject.Parse(Resources.NodeExceptionResponse);

            // Act
            var exceptionEvent = new ExceptionEvent(message);

            // Assert
            Assert.AreEqual(0, exceptionEvent.ExceptionId);
            Assert.AreEqual(3, exceptionEvent.Line);
            Assert.AreEqual(6, exceptionEvent.Column);
            Assert.AreEqual("Error", exceptionEvent.ExceptionName);
            Assert.IsNull(exceptionEvent.ErrorNumber);
            Assert.AreEqual("Error: Mission failed!", exceptionEvent.Description);
            Assert.AreEqual(false, exceptionEvent.Uncaught);
            Assert.IsNotNull(exceptionEvent.Module);
            Assert.AreEqual("server.js", exceptionEvent.Module.Name);
            Assert.AreEqual(false, exceptionEvent.Running);
        }
        private void ReportException(ExceptionEvent exceptionEvent, string errorCode = null) {
            DebuggerClient.RunWithRequestExceptionsHandled(async () => {
                string exceptionName = exceptionEvent.ExceptionName;
                if (!string.IsNullOrEmpty(errorCode)) {
                    exceptionName = string.Format("{0}({1})", exceptionName, errorCode);
                }

                // UNDONE Handle break on unhandled, once just my code is supported
                // Node has a catch all, so there are no uncaught exceptions
                // For now just break always or never
                //if (exceptionTreatment == ExceptionHitTreatment.BreakNever ||
                //    (exceptionTreatment == ExceptionHitTreatment.BreakOnUnhandled && !uncaught)) {
                ExceptionHitTreatment exceptionTreatment = _exceptionHandler.GetExceptionHitTreatment(exceptionName);
                if (exceptionTreatment == ExceptionHitTreatment.BreakNever) {
                    await AutoResumeAsync(false).ConfigureAwait(false);
                    return;
                }

                // We need to get the backtrace before we break, so we request the backtrace
                // and follow up with firing the appropriate event for the break
                bool running = await PerformBacktraceAsync().ConfigureAwait(false);
                Debug.Assert(!running);

                // Handle followup
                EventHandler<ExceptionRaisedEventArgs> exceptionRaised = ExceptionRaised;
                if (exceptionRaised == null) {
                    return;
                }

                string description = exceptionEvent.Description;
                if (description.StartsWith("#<") && description.EndsWith(">")) {
                    // Serialize exception object to get a proper description
                    var tokenSource = new CancellationTokenSource(_timeout);
                    var evaluateCommand = new EvaluateCommand(CommandId, _resultFactory, exceptionEvent.ExceptionId);
                    if (await TrySendRequestAsync(evaluateCommand, tokenSource.Token).ConfigureAwait(false)) {
                        description = evaluateCommand.Result.StringValue;
                    }
                }

                var exception = new NodeException(exceptionName, description);
                exceptionRaised(this, new ExceptionRaisedEventArgs(MainThread, exception, exceptionEvent.Uncaught));
            });
        }
Пример #3
0
        /// <summary>
        /// Handles event message.
        /// </summary>
        /// <param name="message">Message.</param>
        private void HandleEventMessage(JObject message) {
            var eventType = (string)message["event"];
            switch (eventType) {
                case "afterCompile":
                    EventHandler<CompileScriptEventArgs> compileScriptHandler = CompileScriptEvent;
                    if (compileScriptHandler != null) {
                        var compileScriptEvent = new CompileScriptEvent(message);
                        compileScriptHandler(this, new CompileScriptEventArgs(compileScriptEvent));
                    }
                    break;

                case "break":
                    EventHandler<BreakpointEventArgs> breakpointHandler = BreakpointEvent;
                    if (breakpointHandler != null) {
                        var breakpointEvent = new BreakpointEvent(message);
                        breakpointHandler(this, new BreakpointEventArgs(breakpointEvent));
                    }
                    break;

                case "exception":
                    EventHandler<ExceptionEventArgs> exceptionHandler = ExceptionEvent;
                    if (exceptionHandler != null) {
                        var exceptionEvent = new ExceptionEvent(message);
                        exceptionHandler(this, new ExceptionEventArgs(exceptionEvent));
                    }
                    break;

                case "beforeCompile":
                case "breakForCommand":
                case "newFunction":
                case "scriptCollected":
                case "compileError":
                    break;

                default:
                    Debug.Fail(string.Format("Unrecognized type '{0}' in event message: {1}", eventType, message));
                    break;
            }
        }
 public ExceptionEventArgs(ExceptionEvent exceptionEvent) {
     ExceptionEvent = exceptionEvent;
 }