Skip to content

Commit

Permalink
[SPARK-47313][SQL] Added scala.MatchError handling inside QueryExecut…
Browse files Browse the repository at this point in the history
…ion.toInternalError

### What changes were proposed in this pull request?
Created `isInternalError` function that marks `java.lang.NullPointerException`, `java.lang.AssertionError` and newly added `scala.MatchError` as internal errors.

### Why are the changes needed?
Additional error coverage and code refactoring.

### Does this PR introduce _any_ user-facing change?
No

### Was this patch authored or co-authored using generative AI tooling?
No

Closes apache#45438 from stevomitric/stevomitric/match-error-handling.

Authored-by: Stevo Mitric <stevo.mitric@databricks.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
  • Loading branch information
stevomitric authored and sweisdb committed Apr 1, 2024
1 parent 65a0721 commit 156ab34
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -540,20 +540,31 @@ object QueryExecution {
}

/**
* Converts asserts, null pointer exceptions to internal errors.
* Marks null pointer exceptions, asserts and scala match errors as internal errors
*/
private[sql] def toInternalError(msg: String, e: Throwable): Throwable = e match {
case e @ (_: java.lang.NullPointerException | _: java.lang.AssertionError) =>
private[sql] def isInternalError(e: Throwable): Boolean = e match {
case _: java.lang.NullPointerException => true
case _: java.lang.AssertionError => true
case _: scala.MatchError => true
case _ => false
}

/**
* Converts marked exceptions from [[isInternalError]] to internal errors.
*/
private[sql] def toInternalError(msg: String, e: Throwable): Throwable = {
if (isInternalError(e)) {
SparkException.internalError(
msg + " You hit a bug in Spark or the Spark plugins you use. Please, report this bug " +
"to the corresponding communities or vendors, and provide the full stack trace.",
e)
case e: Throwable =>
} else {
e
}
}

/**
* Catches asserts, null pointer exceptions, and converts them to internal errors.
* Catches marked exceptions from [[isInternalError]], and converts them to internal errors.
*/
private[sql] def withInternalError[T](msg: String)(block: => T): T = {
try {
Expand Down

0 comments on commit 156ab34

Please sign in to comment.