From 39d3bc62a7ba16c646bed8d524cf9b929374a790 Mon Sep 17 00:00:00 2001
From: felixcheung <felixcheung_m@hotmail.com>
Date: Sat, 23 Apr 2016 11:08:19 -0700
Subject: [PATCH] [SPARK-14594][SPARKR] check execution return status code

## What changes were proposed in this pull request?

When JVM backend fails without going proper error handling (eg. process crashed), the R error message could be ambiguous.

```
Error in if (returnStatus != 0) { : argument is of length zero
```

This change attempts to make it more clear (however, one would still need to investigate why JVM fails)

## How was this patch tested?

manually

Author: felixcheung <felixcheung_m@hotmail.com>

Closes #12622 from felixcheung/rreturnstatus.
---
 R/pkg/R/backend.R | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/R/pkg/R/backend.R b/R/pkg/R/backend.R
index 49162838b8..6c81492f8b 100644
--- a/R/pkg/R/backend.R
+++ b/R/pkg/R/backend.R
@@ -110,6 +110,9 @@ invokeJava <- function(isStatic, objId, methodName, ...) {
 
   # TODO: check the status code to output error information
   returnStatus <- readInt(conn)
+  if (length(returnStatus) == 0) {
+    stop("No status is returned. Java SparkR backend might have failed.")
+  }
   if (returnStatus != 0) {
     stop(readString(conn))
   }
-- 
GitLab