Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3106e8e

Browse files
thrixtonsuhsteve
andauthoredJun 26, 2020
Expose JVM exceptions (#566)
* Wrap spark exceptions per #472 * Extra tests for JvmException Code styling per guidelines from review by @imback82 in #541 * Add JvmBridge doc link Co-authored-by: Steve Suh <suhsteve@gmail.com> * Fix per code guidelines Co-authored-by: Steve Suh <suhsteve@gmail.com> * Fix cref link * Formatting Co-authored-by: Steve Suh <suhsteve@gmail.com> * Add license header Co-authored-by: Steve Suh <suhsteve@gmail.com>
1 parent 0879fd1 commit 3106e8e

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed
 
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using Microsoft.Spark.Sql;
7+
using Xunit;
8+
9+
namespace Microsoft.Spark.E2ETest.IpcTests
10+
{
11+
[Collection("Spark E2E Tests")]
12+
public class JvmBridgeTests
13+
{
14+
private readonly SparkSession _spark;
15+
16+
public JvmBridgeTests(SparkFixture fixture)
17+
{
18+
_spark = fixture.Spark;
19+
}
20+
21+
[Fact]
22+
public void TestInnerJvmException()
23+
{
24+
try
25+
{
26+
_spark.Sql("THROW!!!");
27+
}
28+
catch (Exception ex)
29+
{
30+
Assert.NotNull(ex.InnerException);
31+
Assert.IsType<JvmException>(ex.InnerException);
32+
Assert.False(string.IsNullOrWhiteSpace(ex.InnerException.Message));
33+
}
34+
}
35+
}
36+
}

‎src/csharp/Microsoft.Spark/Interop/Ipc/JvmBridge.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private object CallJavaMethod(
189189
args);
190190
_logger.LogError(errorMessage);
191191
_logger.LogError(jvmFullStackTrace);
192-
throw new Exception(errorMessage);
192+
throw new Exception(errorMessage, new JvmException(jvmFullStackTrace));
193193
}
194194

195195
char typeAsChar = Convert.ToChar(inputStream.ReadByte());
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
namespace Microsoft.Spark
8+
{
9+
/// <summary>
10+
/// Contains the message returned from the <see cref="Interop.Ipc.JvmBridge"/> on an error.
11+
/// </summary>
12+
public class JvmException : Exception
13+
{
14+
public JvmException(string message)
15+
: base(message)
16+
{
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)
Please sign in to comment.