Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public static void CallEntrypoint(JSMarshalerArgument* arguments_buffer)
}
catch (Exception ex)
{
if (ex is TargetInvocationException refEx && refEx.InnerException != null)
ex = refEx.InnerException;

arg_exc.ToJS(ex);
}
}
Expand Down
20 changes: 17 additions & 3 deletions src/tests/BuildWasmApps/Wasm.Build.Tests/WasmBuildAppTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ public static int Main()
}
}", buildArgs, host, id);

[Theory]
[MemberData(nameof(MainMethodTestData), parameters: new object[] { /*aot*/ false, RunHost.All })]
public void ExceptionFromMain(BuildArgs buildArgs, RunHost host, string id)
=> TestMain("main_exception", """
using System;
using System.Threading.Tasks;

public class TestClass {
public static int Main() => throw new Exception("MessageFromMyException");
}
""", buildArgs, host, id, expectedExitCode: 71, expectedOutput: "Error: MessageFromMyException");

private static string s_bug49588_ProgramCS = @"
using System;
public class TestClass {
Expand Down Expand Up @@ -165,7 +177,9 @@ protected void TestMain(string projectName,
RunHost host,
string id,
string extraProperties = "",
bool? dotnetWasmFromRuntimePack = null)
bool? dotnetWasmFromRuntimePack = null,
int expectedExitCode = 42,
string expectedOutput = "Hello, World!")
{
buildArgs = buildArgs with { ProjectName = projectName };
buildArgs = ExpandBuildArgs(buildArgs, extraProperties);
Expand All @@ -179,8 +193,8 @@ protected void TestMain(string projectName,
InitProject: () => File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), programText),
DotnetWasmFromRuntimePack: dotnetWasmFromRuntimePack));

RunAndTestWasmApp(buildArgs, expectedExitCode: 42,
test: output => Assert.Contains("Hello, World!", output), host: host, id: id);
RunAndTestWasmApp(buildArgs, expectedExitCode: expectedExitCode,
test: output => Assert.Contains(expectedOutput, output), host: host, id: id);
}
}
}