Internal server error when running apropos command without doc index

If the apropos command is run on a server where the documentation
index is not available, it returns an internal server error.

Add handling of document query errors and return a meaningful error
message.

Change-Id: Ic8fdbc504f0666ddb298c66f0e24ea13250977e6
This commit is contained in:
David Pursehouse 2014-02-04 16:37:58 +09:00
parent da48b9de23
commit 957afa6db6

View File

@ -16,6 +16,7 @@ package com.google.gerrit.sshd.commands;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.documentation.QueryDocumentationExecutor;
import com.google.gerrit.server.documentation.QueryDocumentationExecutor.DocQueryException;
import com.google.gerrit.server.documentation.QueryDocumentationExecutor.DocResult;
import com.google.gerrit.sshd.CommandMetaData;
import com.google.gerrit.sshd.SshCommand;
@ -37,10 +38,14 @@ final class AproposCommand extends SshCommand {
@Override
public void run() throws Exception {
List<QueryDocumentationExecutor.DocResult> res = searcher.doQuery(q);
for (DocResult docResult : res) {
stdout.println(String.format("%s:\n%s%s\n", docResult.title, url,
docResult.url));
try {
List<QueryDocumentationExecutor.DocResult> res = searcher.doQuery(q);
for (DocResult docResult : res) {
stdout.println(String.format("%s:\n%s%s\n", docResult.title, url,
docResult.url));
}
} catch (DocQueryException dqe) {
throw new UnloggedFailure(1, "fatal: " + dqe.getMessage());
}
}
}