internal ScriptErrorInfo(IActiveScriptError error, IDictionary <ulong, ScriptInfo> scripts) { ExtractExcepInfo(error); ulong cookie = ExtractSourcePosition <uint>(error.GetSourcePosition); ExtractSourceText(error, cookie, scripts); }
/// <summary> /// Informs the host that an execution error occurred while the engine was running the /// script. /// </summary> /// <param name="err"> Information about the execution error. </param> void IActiveScriptSite.OnScriptError(IActiveScriptError err) { EXCEPINFO exceptionInfo; err.GetExceptionInfo(out exceptionInfo); lastError = string.Format("{0} - {1}", exceptionInfo.bstrSource, exceptionInfo.bstrDescription); }
void IActiveScriptSite.OnScriptError(IActiveScriptError scriptError) { uint sourceContext; int lineNumber; int characterPosition; String message = "Script error: {1}. Error number {0} (0x{0:X8}): {2} at line {3}, column {4}."; String sourceLine = null; System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo; try { scriptError.GetSourceLineText(out sourceLine); if (!String.IsNullOrEmpty(sourceLine)) { message += " Source line: '{5}'."; } } catch { // happens most of the time, but we should still try it. } scriptError.GetSourcePosition(out sourceContext, out lineNumber, out characterPosition); lineNumber++; characterPosition++; scriptError.GetExceptionInfo(out exceptionInfo); _lastException = new ScriptException(String.Format(message, exceptionInfo.scode, exceptionInfo.bstrSource, exceptionInfo.bstrDescription, lineNumber, characterPosition, sourceLine)) { Column = characterPosition, Description = exceptionInfo.bstrDescription, Line = lineNumber, Number = exceptionInfo.scode, Text = sourceLine, ScriptError = (ScriptErrorType)exceptionInfo.scode }; }
private void ExtractSourceText(IActiveScriptError error, ulong cookie, IDictionary <ulong, ScriptInfo> scripts) { if (error == null || scripts == null) { return; } ScriptInfo scriptInfo = null; if (scripts.ContainsKey(cookie)) { scriptInfo = scripts[cookie]; ScriptName = scriptInfo.ScriptName; } try { LineText = error.GetSourceLineText(); } catch { if (scriptInfo != null) { string[] lines = scriptInfo.Code.Split( new string[] { Environment.NewLine }, StringSplitOptions.None); if (lines != null && lines.Length > 0 && LineNumber - 1 <= lines.Length) { LineText = lines[LineNumber - 1]; } } } }
public int OnScriptError(IActiveScriptError scriptError) { Debug.WriteLine("MySite::OnScriptError"); System.Runtime.InteropServices.ComTypes.EXCEPINFO info = scriptError.GetExceptionInfo(); Debug.WriteLine(" Description: " + info.bstrDescription); Debug.WriteLine(" Source: " + info.bstrSource); return(-1); }
void IActiveScriptSite.OnScriptError(IActiveScriptError scriptError) { scriptError.GetExceptionInfo(out EXCEPINFO exceptionInfo); scriptError.GetSourcePosition(out uint sourceContext, out uint lineNumber, out int characterPosition); scriptError.GetSourceLineText(out string sourceLine); var msg = string.Format("'{0}' at line {1}, character {2}:\n\n{3}", exceptionInfo.bstrDescription, lineNumber - 4, characterPosition, sourceLine); System.Windows.Forms.MessageBox.Show(msg, exceptionInfo.bstrSource); }
public static ActiveScriptException Create(IActiveScriptError error) { string source = ""; uint sourceContext = 0; uint lineNumber = 0; int characterPosition = 0; EXCEPINFO excepInfo; string message = ""; try { error.GetSourceLineText(out source); } catch { } try { error.GetSourcePosition(out sourceContext, out lineNumber, out characterPosition); ++lineNumber; ++characterPosition; } catch { } try { error.GetExceptionInfo(out excepInfo); message = string.Format( "Error in [{1}]:\n{0}\nat line {4}({5})\nError Code: {2} (0x{2:X8})\nError WCode: {3}", /* 0 */ excepInfo.bstrDescription, /* 1 */ excepInfo.bstrSource, /* 2 */ excepInfo.scode, /* 3 */ excepInfo.wCode, /* 4 */ lineNumber, /* 5 */ characterPosition, /* 6 */ source); } catch { } return(new ActiveScriptException(message) { LineContent = source, SourceContext = sourceContext, LineNumber = lineNumber, Column = characterPosition, }); }
public void OnScriptError(IActiveScriptError scriptError) { EXCEPINFO exceptionInfo; uint dummy; uint line; int pos; scriptError.GetExceptionInfo(out exceptionInfo); scriptError.GetSourcePosition(out dummy, out line, out pos); exceptionMessage = exceptionInfo.bstrDescription + " (" + line + "," + pos + ")"; GlobalLog.Print("AutoWebProxyScriptWrapper.ScriptHost#" + ValidationHelper.HashString(this) + "::OnScriptError() error:" + ValidationHelper.ToString(exceptionInfo.bstrDescription) + " line:" + line + " pos:" + pos); }
internal static ActiveScriptException Create(IActiveScriptError error) { var source = ""; uint sourceContext = 0; uint lineNumber = 0; var characterPosition = 0; var message = ""; try { error.GetSourceLineText(out source); } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { } try { error.GetSourcePosition(out sourceContext, out lineNumber, out characterPosition); ++lineNumber; ++characterPosition; } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { } try { EXCEPINFO excepInfo; error.GetExceptionInfo(out excepInfo); message = excepInfo.bstrDescription; } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { } return(new ActiveScriptException(message) { LineContent = source, SourceContext = sourceContext, LineNumber = lineNumber, Column = characterPosition, }); }
internal static ActiveScriptException Create(IActiveScriptError error) { var source = ""; uint sourceContext = 0; uint lineNumber = 0; var characterPosition = 0; var message = ""; try { error.GetSourceLineText(out source); } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { } try { error.GetSourcePosition(out sourceContext, out lineNumber, out characterPosition); ++lineNumber; ++characterPosition; } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { } try { EXCEPINFO excepInfo; error.GetExceptionInfo(out excepInfo); message = excepInfo.bstrDescription; } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { } return new ActiveScriptException(message) { LineContent = source, SourceContext = sourceContext, LineNumber = lineNumber, Column = characterPosition, }; }
public void OnScriptError(IActiveScriptError err) { EXCEPINFO excepinfo; int ctx, line, col; err.GetSourcePosition(out ctx, out line, out col); err.GetExceptionInfo(out excepinfo); if (excepinfo.bstrSource.Equals("ScriptControl")) { return; } Console.WriteLine("Script Error ({0},{1}) {2}", line, col, excepinfo.bstrDescription); }
/// <summary> /// Used by ActiveScriptSite to signal error events to this engine. /// </summary> /// <param name="error">The script error object from the IActiveScriptSite instance.</param> internal void OnScriptError(IActiveScriptError error) { this.LastError = new ScriptErrorInfo(error, this.scripts); if (this.LastError.ScriptName == null && scriptToParse != null) { this.LastError.ScriptName = scriptToParse; } var errorOccurred = this.ScriptErrorOccurred; if (errorOccurred != null) { errorOccurred(this, this.LastError); } }
public void OnScriptError(IActiveScriptError scriptError) { uint sourceContext; uint lineNumber; int column; System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo; scriptError.GetSourcePosition(out sourceContext, out lineNumber, out column); scriptError.GetExceptionInfo(out exceptionInfo); string source = exceptionInfo.bstrSource; string description = GetErrorDescription(exceptionInfo); Site.RuntimeError = true; Site.RuntimeException = new RuntimeException(description, source, lineNumber, column); }
int IActiveScriptSite.OnScriptError(IActiveScriptError scriptError) { string sourceLine = null; try { scriptError.GetSourceLineText(out sourceLine); } catch { // happens sometimes... } uint sourceContext; int lineNumber; int characterPosition; scriptError.GetSourcePosition(out sourceContext, out lineNumber, out characterPosition); lineNumber++; characterPosition++; System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo; scriptError.GetExceptionInfo(out exceptionInfo); string message; if (!string.IsNullOrEmpty(sourceLine)) { message = "Script exception: {1}. Error number {0} (0x{0:X8}): {2} at line {3}, column {4}. Source line: '{5}'."; } else { message = "Script exception: {1}. Error number {0} (0x{0:X8}): {2} at line {3}, column {4}."; } LastException = new ScriptException(string.Format(message, exceptionInfo.scode, exceptionInfo.bstrSource, exceptionInfo.bstrDescription, lineNumber, characterPosition, sourceLine)) { Column = characterPosition, Description = exceptionInfo.bstrDescription, Line = lineNumber, Number = exceptionInfo.scode, Text = sourceLine }; return(0); }
void IActiveScriptSite.OnScriptError(IActiveScriptError scriptError) { //Trace.WriteLine("OnScriptError scriptError=" + scriptError); string sourceLine = null; try { scriptError.GetSourceLineText(out sourceLine); } catch { // happens sometimes... } uint sourceContext; int lineNumber; int characterPosition; scriptError.GetSourcePosition(out sourceContext, out lineNumber, out characterPosition); lineNumber++; characterPosition++; EXCEPINFO exceptionInfo; scriptError.GetExceptionInfo(out exceptionInfo); string message; if (!string.IsNullOrEmpty(sourceLine)) { message = "Script exception: {1}. Error number {0} (0x{0:X8}): {2} at line {3}, column {4}. Source line: '{5}'."; } else { message = "Script exception: {1}. Error number {0} (0x{0:X8}): {2} at line {3}, column {4}."; } _lastException = new ScriptException(string.Format(message, exceptionInfo.scode, exceptionInfo.bstrSource, exceptionInfo.bstrDescription, lineNumber, characterPosition, sourceLine)); _lastException.Column = characterPosition; _lastException.Description = exceptionInfo.bstrDescription; _lastException.Line = lineNumber; _lastException.Number = exceptionInfo.scode; _lastException.Text = sourceLine; }
/// <summary> /// Gets a error details /// </summary> /// <param name="error">Instance of Active Script error</param> /// <returns>Error details</returns> private string GetErrorDetails(IActiveScriptError error) { EXCEPINFO excepInfo; error.GetExceptionInfo(out excepInfo); string errorDetails = excepInfo.bstrDescription; if (_jsEngine._processDebugManagerWrapper != null) { string errorLocation = GetErrorLocation(error); if (!string.IsNullOrWhiteSpace(errorLocation)) { errorDetails += Environment.NewLine + errorLocation; } } return(errorDetails); }
public void OnScriptError(IActiveScriptError error) { if ((engine.CurrentScriptFrame != null) && (error != null)) { EXCEPINFO excepInfo; error.GetExceptionInfo(out excepInfo); if (excepInfo.scode == RawCOMHelpers.HResult.E_ABORT) { // Script execution was interrupted explicitly. At this point the script // engine might be in an odd state; the following call seems to get it back // to normal. engine.activeScript.SetScriptState(ScriptState.Started); var description = excepInfo.bstrDescription ?? "Script execution interrupted by host"; engine.CurrentScriptFrame.ScriptError = new ScriptInterruptedException(engine.Name, description, GetDetails(error, description), excepInfo.scode, false, true, null, null); } else { var description = excepInfo.bstrDescription; Exception innerException; if (excepInfo.scode != RawCOMHelpers.HResult.CLEARSCRIPT_E_HOSTEXCEPTION) { innerException = null; } else { innerException = engine.CurrentScriptFrame.HostException; if ((innerException != null) && string.IsNullOrWhiteSpace(description)) { description = innerException.Message; } } engine.CurrentScriptFrame.ScriptError = new ScriptEngineException(engine.Name, description, GetDetails(error, description), excepInfo.scode, false, true, null, innerException); } } }
void IActiveScriptSite.OnScriptError(IActiveScriptError scriptError) { if (scriptError != null) { System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo; scriptError.GetExceptionInfo(out exceptionInfo); uint sourceContext; uint lineNumber; int characterPosition; scriptError.GetSourcePosition(out sourceContext, out lineNumber, out characterPosition); string sourceLine; try { scriptError.GetSourceLineText(out sourceLine); } catch (COMException ex) { if (ex.ErrorCode != -2147467259) { throw; } else { sourceLine = (string)null; } } this.Error.Number = exceptionInfo.scode; this.Error.Column = characterPosition + 1; this.Error.Line = (int)lineNumber + 1; this.Error.Source = exceptionInfo.bstrSource; this.Error.Description = exceptionInfo.bstrDescription; this.Error.HelpFile = exceptionInfo.bstrHelpFile; this.Error.HelpContext = exceptionInfo.dwHelpContext; this.Error.Text = sourceLine; this.Error.SourceContext = this.FSourceContexts[(int)sourceContext]; } throw new COMException((string)null, 1); }
/// <summary> /// Gets a error location /// </summary> /// <param name="error">Instance of Active Script error</param> /// <returns>Error location</returns> private string GetErrorLocation(IActiveScriptError error) { string errorLocation = string.Empty; uint sourceContext; uint lineNumber; int columnNumber; error.GetSourcePosition(out sourceContext, out lineNumber, out columnNumber); ++lineNumber; ++columnNumber; DebugDocument document; if (_jsEngine._debugDocuments.TryGetValue(new UIntPtr(sourceContext), out document)) { string documentName; document.GetName(DocumentNameType.Title, out documentName); errorLocation = string.Format(" at ({0}:{1}:{2})", documentName, lineNumber, columnNumber); } return(errorLocation); }
private void ExtractExcepInfo(IActiveScriptError error) { EXCEPINFO excep; excep = error.GetExceptionInfo(); /* * http://msdn.microsoft.com/en-us/library/windows/desktop/ms221133(v=vs.85).aspx * * wCode * The error code. Error codes should be greater than 1000. * Either this field or the scode field must be filled in; the other must be set to 0. * * scode * A return value that describes the error. Either this field or wCode (but not both) must be filled in; * the other must be set to 0. (16-bit Windows versions only.) * */ ErrorNumber = excep.scode != 0 ? excep.scode : excep.wCode; Source = excep.bstrSource; HelpFile = excep.bstrHelpFile; HelpContext = excep.dwHelpContext; Description = excep.bstrDescription; }
public virtual void OnScriptError(IActiveScriptError scriptError) { throw new ArgumentException(); }
public int OnScriptError(IActiveScriptError scriptError) { Debug.WriteLine("MySite::OnScriptError"); System.Runtime.InteropServices.ComTypes.EXCEPINFO info = scriptError.GetExceptionInfo(); Debug.WriteLine(" Description: " + info.bstrDescription); Debug.WriteLine(" Source: " + info.bstrSource); return -1; }
internal static ActiveScriptException Create(IActiveScriptError error) { string message = string.Empty; int errorCode = 0; short errorWCode = 0; uint sourceContext = 0; string subcategory = string.Empty; string helpLink = string.Empty; uint lineNumber = 0; int columnNumber = 0; string sourceError = string.Empty; try { error.GetSourceLineText(out sourceError); } catch { // Do nothing } try { error.GetSourcePosition(out sourceContext, out lineNumber, out columnNumber); ++lineNumber; ++columnNumber; } catch { // Do nothing } try { EXCEPINFO excepInfo; error.GetExceptionInfo(out excepInfo); message = excepInfo.bstrDescription; subcategory = excepInfo.bstrSource; errorCode = excepInfo.scode; errorWCode = excepInfo.wCode; if (!string.IsNullOrWhiteSpace(excepInfo.bstrHelpFile) && excepInfo.dwHelpContext != 0) { helpLink = string.Format("{0}: {1}", excepInfo.bstrHelpFile, excepInfo.dwHelpContext); } else if (!string.IsNullOrWhiteSpace(excepInfo.bstrHelpFile)) { helpLink = excepInfo.bstrHelpFile; } } catch { // Do nothing } var activeScriptException = new ActiveScriptException(message) { ErrorCode = errorCode, ErrorWCode = errorWCode, SourceContext = sourceContext, Subcategory = subcategory, LineNumber = lineNumber, ColumnNumber = columnNumber, SourceError = sourceError, HelpLink = helpLink, }; return activeScriptException; }
public void OnScriptError(IActiveScriptError err) { EXCEPINFO excepinfo; int ctx, line, col; err.GetSourcePosition(out ctx, out line, out col); err.GetExceptionInfo(out excepinfo); if(excepinfo.bstrSource.Equals("ScriptControl")) { return; } Console.WriteLine("Script Error ({0},{1}) {2}", line, col, excepinfo.bstrDescription); }
public void OnScriptError(IActiveScriptError error) { if ((engine.CurrentScriptFrame != null) && (error != null)) { EXCEPINFO excepInfo; error.GetExceptionInfo(out excepInfo); if (excepInfo.scode == RawCOMHelpers.HResult.E_ABORT) { // Script execution was interrupted explicitly. At this point the script // engine might be in an odd state; the following call seems to get it back // to normal. engine.activeScript.SetScriptState(ScriptState.Started); var description = excepInfo.bstrDescription ?? "Script execution interrupted by host"; engine.CurrentScriptFrame.ScriptError = new ScriptInterruptedException(engine.Name, description, GetDetails(error, description), excepInfo.scode, false, null); } else { var description = excepInfo.bstrDescription; Exception innerException; if (excepInfo.scode != RawCOMHelpers.HResult.CLEARSCRIPT_E_HOSTEXCEPTION) { innerException = null; } else { innerException = engine.CurrentScriptFrame.HostException; if ((innerException != null) && string.IsNullOrWhiteSpace(description)) { description = innerException.Message; } } engine.CurrentScriptFrame.ScriptError = new ScriptEngineException(engine.Name, description, GetDetails(error, description), excepInfo.scode, false, innerException); } } }
/// <summary> /// Informs the host that an execution error occurred while the engine was running the script. /// </summary> /// <param name="scriptError">A host can use this interface to obtain information about the /// execution error</param> public void OnScriptError(IActiveScriptError scriptError) { _lastException = ActiveScriptException.Create(scriptError); OnScriptError(_lastException); }
public static ActiveScriptException Create(IActiveScriptError error) { string source = ""; uint sourceContext = 0; uint lineNumber = 0; int characterPosition = 0; ComTypes.EXCEPINFO excepInfo; string message = ""; try { error.GetSourceLineText(out source); } catch { } try { error.GetSourcePosition(out sourceContext, out lineNumber, out characterPosition); ++lineNumber; ++characterPosition; } catch { } try { error.GetExceptionInfo(out excepInfo); message = string.Format( "Error in [{1}]:\n{0}\nat line {4}({5})\nError Code: {2} (0x{2:X8})\nError WCode: {3}", /* 0 */ excepInfo.bstrDescription, /* 1 */ excepInfo.bstrSource, /* 2 */ excepInfo.scode, /* 3 */ excepInfo.wCode, /* 4 */ lineNumber, /* 5 */ characterPosition, /* 6 */ source); } catch { } return new ActiveScriptException(message) { LineContent = source, SourceContext = sourceContext, LineNumber = lineNumber, Column = characterPosition, }; }
public void OnScriptError(IActiveScriptError error) { _jsEngine._lastException = ActiveScriptException.Create(GetErrorDetails(error), error); }
/// <summary> /// Informs the host that an execution error occurred while the engine was running the script. /// </summary> /// <param name="scriptError">A host can use this interface to obtain information about the /// execution error</param> void IActiveScriptSite.OnScriptError(IActiveScriptError scriptError) { _lastException = ActiveScriptException.Create(scriptError); }
internal static ActiveScriptException Create(IActiveScriptError error) { string message = string.Empty; int errorCode = 0; short errorWCode = 0; uint sourceContext = 0; string subcategory = string.Empty; string helpLink = string.Empty; uint lineNumber = 0; int columnNumber = 0; string sourceError = string.Empty; try { error.GetSourceLineText(out sourceError); } catch { // Do nothing } try { error.GetSourcePosition(out sourceContext, out lineNumber, out columnNumber); ++lineNumber; ++columnNumber; } catch { // Do nothing } try { EXCEPINFO excepInfo; error.GetExceptionInfo(out excepInfo); message = excepInfo.bstrDescription; subcategory = excepInfo.bstrSource; errorCode = excepInfo.scode; errorWCode = excepInfo.wCode; if (!string.IsNullOrWhiteSpace(excepInfo.bstrHelpFile) && excepInfo.dwHelpContext != 0) { helpLink = string.Format("{0}: {1}", excepInfo.bstrHelpFile, excepInfo.dwHelpContext); } else if (!string.IsNullOrWhiteSpace(excepInfo.bstrHelpFile)) { helpLink = excepInfo.bstrHelpFile; } } catch { // Do nothing } var activeScriptException = new ActiveScriptException(message) { ErrorCode = errorCode, ErrorWCode = errorWCode, SourceContext = sourceContext, Subcategory = subcategory, LineNumber = lineNumber, ColumnNumber = columnNumber, SourceError = sourceError, HelpLink = helpLink, }; return(activeScriptException); }
void IActiveScriptSite.OnScriptError(IActiveScriptError scriptError) { //Trace.WriteLine("OnScriptError scriptError=" + scriptError); string sourceLine = null; try { scriptError.GetSourceLineText(out sourceLine); } catch { // happens sometimes... } uint sourceContext; int lineNumber; int characterPosition; scriptError.GetSourcePosition(out sourceContext, out lineNumber, out characterPosition); lineNumber++; characterPosition++; System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo; scriptError.GetExceptionInfo(out exceptionInfo); string message; if (!string.IsNullOrEmpty(sourceLine)) { message = "Script exception: {1}. Error number {0} (0x{0:X8}): {2} at line {3}, column {4}. Source line: '{5}'."; } else { message = "Script exception: {1}. Error number {0} (0x{0:X8}): {2} at line {3}, column {4}."; } LastException = new ScriptException(string.Format(message, exceptionInfo.scode, exceptionInfo.bstrSource, exceptionInfo.bstrDescription, lineNumber, characterPosition, sourceLine)); LastException.Column = characterPosition; LastException.Description = exceptionInfo.bstrDescription; LastException.Line = lineNumber; LastException.Number = exceptionInfo.scode; LastException.Text = sourceLine; }
public void OnScriptError(IActiveScriptError error) { this.scriptEngine.OnScriptError(error); }
public void OnScriptError(IActiveScriptError scriptError) { lastScriptException = ActiveScriptException.Create(scriptError); }