Skip to content

Commit ae21840

Browse files
acoppesBenjamin-Dobell
authored andcommitted
fix: include original exception stacktrace when calling a method from a c# object from lua side
1 parent e9aaa38 commit ae21840

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/MoonSharp.Interpreter.Tests/EndToEnd/ErrorHandlingTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,36 @@ public void Errors_Get_OriginalException()
154154
}
155155
}
156156

157+
private class ClassWithMember
158+
{
159+
public void MethodWithError()
160+
{
161+
throw new NullReferenceException();
162+
}
163+
}
164+
165+
[Test]
166+
public void Errors_Get_OriginalException_WhenUsingMember()
167+
{
168+
string luaScript =
169+
@"
170+
objectWithMethod.MethodWithError();
171+
";
172+
Script script = new Script(CoreModules.None);
173+
174+
UserData.RegisterType<ClassWithMember>();
175+
176+
script.Globals["objectWithMethod"] = new ClassWithMember();
177+
178+
try
179+
{
180+
script.DoString(luaScript);
181+
}
182+
catch (Exception e)
183+
{
184+
Assert.IsTrue(e.StackTrace.Contains("MoonSharp.Interpreter.Tests.EndToEnd.ErrorHandlingTests.ClassWithMember.MethodWithError() "), "Exception should contain c# error line");
185+
}
186+
}
187+
157188
}
158189
}

src/MoonSharp.Interpreter/Interop/StandardDescriptors/ReflectionMemberDescriptors/MethodMemberDescriptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ public override DynValue Execute(Script script, object obj, ScriptExecutionConte
212212

213213
return BuildReturnValue(script, outParams, pars, retv);
214214
}
215-
catch (Exception e)
215+
catch
216216
{
217-
throw e;
217+
throw;
218218
}
219219
}
220220

0 commit comments

Comments
 (0)