Don't NPE when Throwable is missing message (#11102)

Looks like `Throwable` thrown by the execution may be missing a message,
which later crashes when we want to send it over the wire.
Added some guards to prevent NPE.
This commit is contained in:
Hubert Plociniczak 2024-09-17 16:37:38 +02:00 committed by GitHub
parent 3dd0fb95ae
commit 031300dfb3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,6 +6,8 @@ import org.enso.interpreter.instrument.execution.{Executable, RuntimeContext}
import org.enso.interpreter.runtime.state.ExecutionEnvironment
import org.enso.polyglot.runtime.Runtime.Api
import java.util.logging.Level
/** A job responsible for executing a call stack for the provided context.
*
* @param contextId an identifier of a context to execute
@ -31,11 +33,25 @@ class ExecuteJob(
runImpl
} catch {
case t: Throwable =>
ctx.executionService.getLogger.log(Level.SEVERE, "Failed to execute", t)
val errorMsg = if (t.getMessage == null) {
if (t.getCause == null) {
t.getClass.toString
} else {
val cause = t.getCause
if (cause.getMessage == null) {
cause.getClass.toString
} else {
cause.getMessage
}
}
} else t.getMessage
ctx.endpoint.sendToClient(
Api.Response(
Api.ExecutionFailed(
contextId,
Api.ExecutionResult.Failure(t.getMessage, None)
Api.ExecutionResult.Failure(errorMsg, None)
)
)
)