Fix stack trace when encountering a checkstyle error

Change-Id: If1b7edd9aaf1779251b339dbef254fcc1b0e4690
This commit is contained in:
Ray Milkey 2018-01-16 15:00:50 -08:00
parent d008dbeb7f
commit 0e44012994
2 changed files with 15 additions and 5 deletions

View File

@ -175,7 +175,11 @@ public final class BuckDaemon {
try { try {
try { try {
socket.setSoTimeout(1_000); //reads should time out after 1 second socket.setSoTimeout(1_000); //reads should time out after 1 second
BuckTaskContext context = new BuckTaskContext(socket.getInputStream()); BuckTaskContext context = BuckTaskContext.createBuckTaskContext(socket.getInputStream());
if (context == null) {
socket.close();
return;
}
String taskName = context.taskName(); String taskName = context.taskName();
BuckTask task = tasks.get(taskName); BuckTask task = tasks.get(taskName);

View File

@ -36,10 +36,16 @@ public class BuckTaskContext {
private final ImmutableList<String> input; private final ImmutableList<String> input;
private final List<String> output; private final List<String> output;
BuckTaskContext(InputStream inputStream) throws IOException { public static BuckTaskContext createBuckTaskContext(InputStream inputStream) throws IOException {
ImmutableList<String> lines = slurpInput(inputStream); ImmutableList<String> lines = slurpInput(inputStream);
checkArgument(lines.size() >= 1 && !lines.get(0).isEmpty(), if (lines.size() == 0) {
"Request must contain at least task type"); return null;
} else {
return new BuckTaskContext(lines);
}
}
BuckTaskContext(ImmutableList<String> lines) {
this.taskName = lines.get(0); this.taskName = lines.get(0);
this.input = lines.subList(1, lines.size()); this.input = lines.subList(1, lines.size());
this.output = Lists.newArrayList(); this.output = Lists.newArrayList();
@ -55,7 +61,7 @@ public class BuckTaskContext {
private static ImmutableList<String> slurpInput(InputStream stream) throws IOException { private static ImmutableList<String> slurpInput(InputStream stream) throws IOException {
ImmutableList.Builder<String> lines = ImmutableList.builder(); ImmutableList.Builder<String> lines = ImmutableList.builder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream)); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream));
while(true) { while (true) {
String line = bufferedReader.readLine(); String line = bufferedReader.readLine();
if (line == null || line.trim().length() == 0) { if (line == null || line.trim().length() == 0) {
// Empty line or EOF // Empty line or EOF