Skip to content

Commit 1dfd56e

Browse files
committed
Adding the error stream output from the shell process to the detail message
of the RuntimeException thrown when the pipe to the subprocess is broken.
1 parent 8d2eaba commit 1dfd56e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/jvm/backtype/storm/utils/ShellProcess.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22

33
import backtype.storm.task.TopologyContext;
44
import java.io.BufferedReader;
5+
import java.io.InputStream;
56
import java.io.InputStreamReader;
67
import java.io.DataOutputStream;
78
import java.io.File;
89
import java.io.IOException;
910
import java.util.Map;
1011
import java.util.List;
12+
13+
import org.apache.commons.io.IOUtils;
1114
import org.json.simple.JSONObject;
1215
import org.json.simple.JSONValue;
1316

1417
public class ShellProcess {
1518
private DataOutputStream processIn;
1619
private BufferedReader processOut;
20+
private InputStream processErrorStream;
1721
private Process _subprocess;
1822
private String[] command;
1923

@@ -28,6 +32,7 @@ public Number launch(Map conf, TopologyContext context) throws IOException {
2832

2933
processIn = new DataOutputStream(_subprocess.getOutputStream());
3034
processOut = new BufferedReader(new InputStreamReader(_subprocess.getInputStream()));
35+
processErrorStream = _subprocess.getErrorStream();
3136

3237
JSONObject setupInfo = new JSONObject();
3338
setupInfo.put("pidDir", context.getPIDDir());
@@ -69,8 +74,19 @@ private String readString() throws IOException {
6974
//synchronized (processOut) {
7075
while (true) {
7176
String subline = processOut.readLine();
72-
if(subline==null)
73-
throw new RuntimeException("Pipe to subprocess seems to be broken! Currently read output: " + line.toString());
77+
if(subline==null) {
78+
StringBuilder errorMessage = new StringBuilder();
79+
errorMessage.append("Pipe to subprocess seems to be broken!");
80+
if (line.length() == 0) {
81+
errorMessage.append(" No output read.\n");
82+
}
83+
else {
84+
errorMessage.append(" Currently read output: " + line.toString() + "\n");
85+
}
86+
errorMessage.append("Shell Process Exception:\n");
87+
errorMessage.append(IOUtils.toString(processErrorStream) + "\n");
88+
throw new RuntimeException(errorMessage.toString());
89+
}
7490
if(subline.equals("end")) {
7591
break;
7692
}

0 commit comments

Comments
 (0)