Exemplo n.º 1
0
        public ContextError(Exception ex)
        {
            message = ex.Message;
            trace   = new List <TraceData>();
            JavascriptException jsEx = ex as JavascriptException;

            if (jsEx != null)
            {
                // Remove refs to Host environment & output javascript error
                message = jsEx.Message.Replace("TrifleJS.Host+", "");
                trace.Add(new TraceData
                {
                    file = jsEx.Source,
                    line = jsEx.Line,
                    col  = jsEx.StartColumn,
                    func = jsEx.TargetSite.Name
                });
            }
            else
            {
                foreach (var frame in new StackTrace(ex).GetFrames())
                {
                    trace.Add(new TraceData
                    {
                        file = frame.GetFileName(),
                        line = frame.GetFileLineNumber(),
                        col  = frame.GetFileColumnNumber(),
                        func = frame.GetMethod().Name
                    });
                }
            }
        }
Exemplo n.º 2
0
        public void LogScriptError(string file, string instanceId, JavascriptException ex, string subSource = null)
        {
            var additionalData = new StringBuilder();

            if (ex.Data.Contains("V8SourceLine"))
            {
                additionalData.Append("Source line: ");
                additionalData.AppendLine(ex.Data["V8SourceLine"] as string);
            }

            if (ex.Data.Contains("V8StackTrace"))
            {
                additionalData.Append("Stack trace: ");
                additionalData.AppendLine(ex.Data["V8StackTrace"] as string);
            }

            if (!String.IsNullOrEmpty(ex.Source))
            {
                subSource = String.IsNullOrEmpty(subSource) ? ex.Source : "{0}/{1}".FormatString(subSource, ex.Source);
            }

            if (additionalData.Length > 0)
            {
                additionalData = additionalData.Insert(0, Environment.NewLine);
            }

            var message = "JS Error '{0}' at {1}line {2}, columns {3}:{4}.{5}".FormatString(ex.Message, String.IsNullOrEmpty(subSource) ? String.Empty : "{0}, ".FormatString(subSource), ex.Line, ex.StartColumn, ex.EndColumn, additionalData.ToString());

            Logger.LogError(message, instanceId);
            MonitoringFacade.AddLog(instanceId, LogMessageTypeEnum.Error, message);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles an exception
        /// </summary>
        /// <param name="ex"></param>
        public static void Handle(Exception ex)
        {
            List <Dictionary <string, object> > traceData = new List <Dictionary <string, object> >();
            JavascriptException jsEx = ex as JavascriptException;
            string message           = ex.Message;

            if (jsEx != null)
            {
                // Remove refs to Host environment & output javascript error
                message = jsEx.Message.Replace("TrifleJS.Host+", "");
                traceData.Add(new Dictionary <string, object> {
                    { "file", jsEx.Source },
                    { "line", jsEx.Line },
                    { "col", jsEx.StartColumn },
                    { "function", jsEx.TargetSite.Name }
                });
            }
            else
            {
                StackTrace trace = new StackTrace(ex);
                foreach (var frame in trace.GetFrames())
                {
                    traceData.Add(new Dictionary <string, object> {
                        { "file", frame.GetFileName() },
                        { "line", frame.GetFileLineNumber() },
                        { "col", frame.GetFileColumnNumber() },
                        { "function", frame.GetMethod().Name }
                    });
                }
            }
            var err = traceData[0];

            Console.error(String.Format("{0} ({1},{2}): {3}", err.Get("file"), err.Get("line"), err.Get("col"), message));
        }
Exemplo n.º 4
0
            public void OnUncaughtException(IWebBrowser browserControl, IBrowser browser, IFrame frame, CefSharp.JavascriptException exception)
            {
                if (JavascriptExecutor.IsInternalException(exception.Message))
                {
                    // ignore internal exceptions, they will be handled by the EvaluateScript caller
                    return;
                }
                var javascriptException = new JavascriptException(exception.Message, exception.StackTrace);

                OwnerWebView.ForwardUnhandledAsyncException(javascriptException, frame.Name);
            }
Exemplo n.º 5
0
        private void OnJavascriptUncaughException(object sender, JavascriptUncaughtExceptionEventArgs e)
        {
            if (JavascriptExecutor.IsInternalException(e.Message))
            {
                // ignore internal exceptions, they will be handled by the EvaluateScript caller
                return;
            }
            var javascriptException = new JavascriptException(e.Message, e.StackFrames);

            ForwardUnhandledAsyncException(javascriptException, e.Frame.Name);
        }
Exemplo n.º 6
0
        private TestResults BuildFailTestResultFromException(string fileName, JavascriptException ex)
        {
            Trace.Assert(!String.IsNullOrWhiteSpace(fileName));
            Trace.Assert(ex != null);

            TestResults tr = new TestResults(fileName);

            tr.AddFailedTest(fileName + " - " + GetNiceExceptionMessage(ex));
            Console.WriteLine("Exception: " + ex);
            return(tr);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Handles an exception
        /// </summary>
        /// <param name="ex"></param>
        public static void Handle(Exception ex)
        {
            JavascriptException jsEx = ex as JavascriptException;

            if (jsEx != null)
            {
                // Remove refs to Host environment & output javascript error
                string message = jsEx.Message.Replace("TrifleJS.Host+", "");
                Console.error(String.Format("{0} ({1},{2}): {3}", jsEx.Source, jsEx.Line, jsEx.StartColumn, message));
            }
            else
            {
                Console.error(String.Format("{0}: {1}", ex.Source, ex.Message));
            }
        }
            public void OnUncaughtException(IWebBrowser browserControl, IBrowser browser, IFrame frame, CefSharp.JavascriptException exception)
            {
                if (JavascriptExecutor.IsInternalException(exception.Message))
                {
                    // ignore internal exceptions, they will be handled by the EvaluateScript caller
                    return;
                }
                var javascriptException = new JavascriptException(
                    exception.Message,
                    exception.StackTrace.Select(l => {
                    var location = l.SourceName + ":" + l.LineNumber + ":" + l.ColumnNumber;
                    return(JavascriptException.AtSeparator + (string.IsNullOrEmpty(l.FunctionName) ? location : l.FunctionName + " (" + location + ")"));
                }).ToArray());

                OwnerWebView.ForwardUnhandledAsyncException(javascriptException);
            }
Exemplo n.º 9
0
 void IRenderProcessMessageHandler.OnUncaughtException(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, JavascriptException exception)
 {
 }
Exemplo n.º 10
0
 void IRenderProcessMessageHandler.OnUncaughtException(IWebBrowser browserControl, IBrowser browser, IFrame frame, JavascriptException exception)
 {
     Console.WriteLine("OnUncaughtException() - " + exception.Message);
 }
 public void OnUncaughtException(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, JavascriptException exception)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 12
0
        private TestResults BuildFailTestResultFromException(string fileName, JavascriptException ex)
        {
            Trace.Assert(!String.IsNullOrWhiteSpace(fileName));
              Trace.Assert(ex != null);

              TestResults tr = new TestResults(fileName);
              tr.AddFailedTest(fileName + " - " + GetNiceExceptionMessage(ex));
              Console.WriteLine("Exception: " + ex);
              return tr;
        }
Exemplo n.º 13
0
        /*static SubProcess()
        {
            StartProcessKiller();
        }

        /// <summary>
        /// Helper to start the process killer
        /// </summary>
        private static void StartProcessKiller()
        {
            try
            {
                Process pkp = new Process();
                pkp.StartInfo = new ProcessStartInfo("ProcessKiller.exe", Process.GetCurrentProcess().Id.ToString());
                pkp.StartInfo.RedirectStandardInput = true;
                pkp.StartInfo.UseShellExecute = false;

                pkp.EnableRaisingEvents = true;
                pkp.Exited += new EventHandler(pkp_Exited);

                if (!pkp.Start())
                {
                    Exception e = new JavascriptException("Could not start sub process");
                    log.Error("Error starting Process Killer sub process", e);

                    throw e;
                }

                log.Info("Process Killer started, parent process id (" + Process.GetCurrentProcess().Id.ToString() + "): " + pkp.ToString());

                SubProcessIdWriteStream = pkp.StandardInput;

                HashSet<Process> subProcesses;
                using (TimedLock.Lock(SubProcesses))
                    subProcesses = new HashSet<Process>(SubProcesses);

                using (TimedLock.Lock(SubProcessIdWriteStream))
                    foreach (Process subProcess in subProcesses)
                        SubProcessIdWriteStream.WriteLine(subProcess.Id.ToString());

            }
            catch (Exception e)
            {
                log.Error("Error starting process killer", e);
            }
        }

        static void pkp_Exited(object sender, EventArgs e)
        {
            ((Process)sender).Exited -= new EventHandler(pkp_Exited);
            StartProcessKiller();
        }*/
        public SubProcess(FileHandlerFactoryLocator fileHandlerFactoryLocator)
        {
            _Process = new Process();
            _Process.StartInfo = new ProcessStartInfo("java", "-cp ." + Path.DirectorySeparatorChar + "js.jar -jar JavascriptProcess.jar " + Process.GetCurrentProcess().Id.ToString());
            _Process.StartInfo.RedirectStandardInput = true;
            _Process.StartInfo.RedirectStandardOutput = true;
            _Process.StartInfo.RedirectStandardError = true;
            _Process.StartInfo.UseShellExecute = false;
            _Process.EnableRaisingEvents = true;
            _Process.Exited += new EventHandler(Process_Exited);

            log.Info("Starting sub process");

            if (!Process.Start())
            {
                Exception e = new JavascriptException("Could not start sub process");
                log.Error("Error starting Javascript sub process", e);

                throw e;
            }

            log.Info("Javascript sub process started: " + _Process.ToString());

            if (null != SubProcessIdWriteStream)
                using (TimedLock.Lock(SubProcessIdWriteStream))
                    SubProcessIdWriteStream.WriteLine(_Process.Id.ToString());

            JSONSender = new JsonWriter(_Process.StandardInput);

            // Failed attempt to handle processes without Threads
            _Process.ErrorDataReceived += new DataReceivedEventHandler(Process_ErrorDataReceived);
            _Process.BeginErrorReadLine();

            using (TimedLock.Lock(SubProcesses))
                SubProcesses.Add(_Process);
        }
Exemplo n.º 14
0
 public ScritpException(string js, JavascriptException ex)
     : base(string.Format("执行JS出现异常", ex.StartColumn
                          , ex.EndColumn, ex.Line, ex.Source), ex)
 {
 }
Exemplo n.º 15
0
        public void LogJavascriptError(JavascriptError javascriptError)
        {
            var javascriptException = new JavascriptException(javascriptError.Message, javascriptError.Stack);

            logger.LogError(javascriptException, "Javascript error");
        }
Exemplo n.º 16
0
 public void OnUncaughtException(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, JavascriptException exception)
 {
 }
Exemplo n.º 17
0
 public void OnUncaughtException(IWebBrowser browserControl, IBrowser browser, IFrame frame, JavascriptException exception)
 {
 }
Exemplo n.º 18
0
 public void OnUncaughtException(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame,
                                 JavascriptException exception)
 {
     Debug.WriteLine(exception);
 }