Skip to content

Commit 9681421

Browse files
committed
Fix error details from VBScript in some cases
Fix a case where error details including the stack trace were not getting reported when they should. Also added a test case that proves that the error details in this case get reported correctly. Note, error handling is quite complex in here, so I'm not 100% certain this is always the right thing to do. We also have some indication that the problem may be intermittent, though I haven't been able to prove that yet.
1 parent 42cdf0e commit 9681421

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

ClearScript/Windows/WindowsScriptEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ private void ThrowScriptError(Exception exception)
505505
var comException = exception as COMException;
506506
if (comException != null)
507507
{
508-
if (comException.ErrorCode == HResult.SCRIPT_E_REPORTED)
508+
if (CurrentScriptFrame.ScriptError != null || CurrentScriptFrame.PendingScriptError != null)
509509
{
510510
// a script error was reported; the corresponding exception should be in the script frame
511511
ThrowScriptError(CurrentScriptFrame.ScriptError ?? CurrentScriptFrame.PendingScriptError);

ClearScriptTest/VBScriptEngineTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,28 @@ public void VBScriptEngine_AccessContext_Default()
468468
engine.Execute("test.PrivateMethod()");
469469
}
470470

471+
[TestMethod, TestCategory("VBScriptEngine")]
472+
public void VBScriptEngine_ExceptionDetails()
473+
{
474+
engine.AddHostObject("test", this);
475+
engine.Execute("Sub Run\ntest.NonExistent = 3\nEnd Sub");
476+
try
477+
{
478+
engine.Invoke("Run");
479+
Assert.Fail("Expected failure");
480+
}
481+
catch ( ScriptEngineException see )
482+
{
483+
Assert.AreEqual(
484+
"Object doesn't support this property or method: 'test.NonExistent'\n at Run (Script [3]:1:0) -> test.NonExistent = 3",
485+
see.ErrorDetails, "Details message was wrong");
486+
}
487+
catch ( Exception ex )
488+
{
489+
Assert.Fail("Wrong exception thrown: " + ex);
490+
}
491+
}
492+
471493
[TestMethod, TestCategory("VBScriptEngine")]
472494
public void VBScriptEngine_AccessContext_Private()
473495
{

0 commit comments

Comments
 (0)