Exemple #1
0
        private JsRuntimeException ConvertScriptEngineExceptionToJsRuntimeException(
            OriginalJsException scriptEngineException)
        {
            string errorDetails = scriptEngineException.ErrorDetails;
            int    lineNumber   = 0;
            int    columnNumber = 0;

            Match errorStringMatch = _errorStringRegex.Match(errorDetails);

            if (errorStringMatch.Success)
            {
                GroupCollection errorStringGroups = errorStringMatch.Groups;

                lineNumber   = int.Parse(errorStringGroups["lineNumber"].Value);
                columnNumber = int.Parse(errorStringGroups["columnNumber"].Value);
            }

            var jsRuntimeException = new JsRuntimeException(errorDetails, ENGINE_NAME, ENGINE_VERSION,
                                                            scriptEngineException)
            {
                LineNumber   = lineNumber,
                ColumnNumber = columnNumber,
                Source       = scriptEngineException.Source,
                HelpLink     = scriptEngineException.HelpLink
            };

            return(jsRuntimeException);
        }
Exemple #2
0
        /// <summary>
        /// translate script engine exception to message for log
        /// </summary>
        /// <param name="ex"></param>
        /// <returns></returns>
        private static string getScriptEngineExceptionMessage(Microsoft.ClearScript.ScriptEngineException ex, string scopeDescription)
        {
            string errorMsg = "Clearscript exception, " + scopeDescription;

            errorMsg += "\nex [" + ex.Message + "]";
            if (ex.Data.Count > 0)
            {
                foreach (DictionaryEntry de in ex.Data)
                {
                    errorMsg += "\nkey [" + de.Key.ToString() + "] = [" + de.Value + "]";
                }
            }
            if (ex.ErrorDetails != null)
            {
                errorMsg += "\n" + ex.ErrorDetails;
            }
            if (ex.InnerException != null)
            {
                errorMsg += "\nInner Exception: " + ex.InnerException.ToString();
            }
            return(errorMsg);
        }
Exemple #3
0
        private static WrapperException WrapScriptEngineException(OriginalException originalException)
        {
            WrapperException wrapperException;
            string           message = originalException.Message;
            string           messageWithErrorLocation = originalException.ErrorDetails;
            string           description  = message;
            string           type         = string.Empty;
            string           documentName = string.Empty;
            int    lineNumber             = 0;
            int    columnNumber           = 0;
            string callStack      = string.Empty;
            string sourceFragment = string.Empty;

            if (originalException.IsFatal)
            {
                if (message == "The V8 runtime has exceeded its memory limit")
                {
                    wrapperException = new WrapperRuntimeException(message, EngineName, EngineVersion,
                                                                   originalException);
                }
                else
                {
                    wrapperException = new WrapperFatalException(message, EngineName, EngineVersion,
                                                                 originalException);
                }
            }
            else
            {
                Match messageWithTypeMatch = _errorMessageWithTypeRegex.Match(message);
                if (messageWithTypeMatch.Success)
                {
                    GroupCollection messageWithTypeGroups = messageWithTypeMatch.Groups;
                    type        = messageWithTypeGroups["type"].Value;
                    description = messageWithTypeGroups["description"].Value;
                    var errorLocationItems = new ErrorLocationItem[0];

                    if (message.Length < messageWithErrorLocation.Length)
                    {
                        string errorLocation = messageWithErrorLocation
                                               .TrimStart(message)
                                               .TrimStart(new char[] { '\n', '\r' })
                        ;

                        errorLocationItems = JsErrorHelpers.ParseErrorLocation(errorLocation);
                        if (errorLocationItems.Length > 0)
                        {
                            ErrorLocationItem firstErrorLocationItem = errorLocationItems[0];

                            documentName = firstErrorLocationItem.DocumentName;
                            lineNumber   = firstErrorLocationItem.LineNumber;
                            columnNumber = firstErrorLocationItem.ColumnNumber;
                            string sourceLine = firstErrorLocationItem.SourceFragment;
                            sourceFragment = TextHelpers.GetTextFragmentFromLine(sourceLine, columnNumber);

                            firstErrorLocationItem.SourceFragment = sourceFragment;
                        }
                    }

                    WrapperScriptException wrapperScriptException;
                    if (type == JsErrorType.Syntax)
                    {
                        message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, documentName,
                                                                            lineNumber, columnNumber, sourceFragment);

                        wrapperScriptException = new WrapperCompilationException(message, EngineName, EngineVersion,
                                                                                 originalException);
                    }
                    else
                    {
                        callStack = JsErrorHelpers.StringifyErrorLocationItems(errorLocationItems, true);
                        string callStackWithSourceFragment = JsErrorHelpers.StringifyErrorLocationItems(
                            errorLocationItems);
                        message = JsErrorHelpers.GenerateScriptErrorMessage(type, description,
                                                                            callStackWithSourceFragment);

                        wrapperScriptException = new WrapperRuntimeException(message, EngineName, EngineVersion,
                                                                             originalException)
                        {
                            CallStack = callStack
                        };
                    }

                    wrapperScriptException.Type           = type;
                    wrapperScriptException.DocumentName   = documentName;
                    wrapperScriptException.LineNumber     = lineNumber;
                    wrapperScriptException.ColumnNumber   = columnNumber;
                    wrapperScriptException.SourceFragment = sourceFragment;

                    wrapperException = wrapperScriptException;
                }
                else
                {
                    wrapperException = new WrapperException(message, EngineName, EngineVersion,
                                                            originalException);
                }
            }

            wrapperException.Description = description;

            return(wrapperException);
        }