Skip to content

Commit

Permalink
[release/7.0-rc1] [wasm] Unwrap exception when calling entrypoint (#7…
Browse files Browse the repository at this point in the history
…4263)

* Unwrap exception,

* WBT.

Co-authored-by: Marek Fišera <mara@neptuo.com>
  • Loading branch information
github-actions[bot] and maraf committed Aug 20, 2022
1 parent 8196f9a commit b3ef656
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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);
}
}
}

0 comments on commit b3ef656

Please sign in to comment.