private static WrapperTimeoutException WrapTimeoutException(TimeoutException originalTimeoutException) { string message = CoreStrings.Runtime_ScriptTimeoutExceeded; string description = message; var wrapperTimeoutException = new WrapperTimeoutException(message, EngineName, EngineVersion, originalTimeoutException) { Description = description }; return(wrapperTimeoutException); }
private WrapperException WrapInvocationException(InvocationException originalException) { WrapperException wrapperException; string message = originalException.Message; string description = string.Empty; if (_timeoutErrorMessage.IsMatch(message)) { message = CoreStrings.Runtime_ScriptTimeoutExceeded; description = message; var wrapperTimeoutException = new WrapperTimeoutException(message, EngineName, _engineVersion, originalException) { Description = description }; return(wrapperTimeoutException); } string documentName = string.Empty; int lineNumber = 0; int columnNumber = 0; string sourceLine = string.Empty; Match detailsMatch = _errorDetailsRegex.Match(message); int detailsLength = 0; if (detailsMatch.Success) { GroupCollection detailsGroups = detailsMatch.Groups; description = detailsGroups["description"].Value; documentName = detailsGroups["documentName"].Success ? detailsGroups["documentName"].Value : string.Empty; lineNumber = detailsGroups["lineNumber"].Success ? int.Parse(detailsGroups["lineNumber"].Value) : 0; columnNumber = NodeJsErrorHelpers.GetColumnCountFromLine(detailsGroups["pointer"].Value); sourceLine = detailsGroups["sourceLine"].Value; detailsLength = detailsMatch.Length; } message = detailsLength > 0 ? message.Substring(detailsLength) : message; Match messageWithTypeMatch = _errorMessageWithTypeRegex.Match(message); if (messageWithTypeMatch.Success) { GroupCollection messageWithTypeGroups = messageWithTypeMatch.Groups; string type = messageWithTypeGroups["type"].Value; description = messageWithTypeGroups["description"].Value; string sourceFragment = TextHelpers.GetTextFragmentFromLine(sourceLine, columnNumber); WrapperScriptException wrapperScriptException; if (type == JsErrorType.Syntax) { message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, documentName, lineNumber, columnNumber, sourceFragment); wrapperScriptException = new WrapperCompilationException(message, EngineName, _engineVersion, originalException); } else if (type == "UsageError") { wrapperException = new WrapperUsageException(description, EngineName, _engineVersion, originalException); wrapperException.Description = description; return(wrapperException); } else { var errorLocationItems = new ErrorLocationItem[0]; int messageLength = message.Length; int messageWithTypeLength = messageWithTypeMatch.Length; if (messageWithTypeLength < messageLength) { string errorLocation = message.Substring(messageWithTypeLength); errorLocationItems = NodeJsErrorHelpers.ParseErrorLocation(errorLocation); errorLocationItems = FilterErrorLocationItems(errorLocationItems); if (errorLocationItems.Length > 0) { ErrorLocationItem firstErrorLocationItem = errorLocationItems[0]; documentName = firstErrorLocationItem.DocumentName; lineNumber = firstErrorLocationItem.LineNumber; columnNumber = firstErrorLocationItem.ColumnNumber; firstErrorLocationItem.SourceFragment = sourceFragment; } } string 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); }