Skip to content

Commit

Permalink
Add useful message when no input from terminal (#29369)
Browse files Browse the repository at this point in the history
Today when a user runs a CLI tool with standard input closed and no tty
attached, the result from reading is null and this usually leads to a
null pointer exception when we try to parse this input. This arises for
example when the user runs the plugin installer through a Docker
container without leaving standard input open and attaching a tty
(docker exec <container ID> bin/elasticsearch-plugin install). When we
try to read that the user accepts the plugin requiring additional
security permissions we will get back null. This commit addresses this
for all cases by throwing an illegal state exception. The solution for
the user is leave standard input open and attach a tty (or, for some
tools, use batch mode).
  • Loading branch information
jasontedor authored Apr 11, 2018
1 parent c341b41 commit 663a52a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/cli/src/main/java/org/elasticsearch/cli/Terminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ public String readText(String text) {
getWriter().print(text);
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, Charset.defaultCharset()));
try {
return reader.readLine();
final String line = reader.readLine();
if (line == null) {
throw new IllegalStateException("unable to read from standard input; is standard input open and a tty attached?");
}
return line;
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
Expand Down

0 comments on commit 663a52a

Please sign in to comment.