Skip to content

Commit 080d845

Browse files
committed
Add useful message when no input from terminal (#29369)
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).
1 parent 990cf58 commit 080d845

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

server/cli/src/main/java/org/elasticsearch/cli/Terminal.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ public String readText(String text) {
163163
getWriter().print(text);
164164
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, Charset.defaultCharset()));
165165
try {
166-
return reader.readLine();
166+
final String line = reader.readLine();
167+
if (line == null) {
168+
throw new IllegalStateException("unable to read from standard input; is standard input open and a tty attached?");
169+
}
170+
return line;
167171
} catch (IOException ioe) {
168172
throw new RuntimeException(ioe);
169173
}

0 commit comments

Comments
 (0)