SOLR-482: add some improved exception information for CSV files that fail

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1063333 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2011-01-25 16:14:59 +00:00
parent 68f67a4b23
commit 27fe1ca874
2 changed files with 26 additions and 3 deletions

View File

@ -161,6 +161,8 @@ Bug Fixes
* SOLR-2127: Fixed serialization of default core and indentation of solr.xml when serializing.
(Ephraim Ofir, Mark Miller)
* SOLR-482: Provide more exception handling in CSVLoader (gsingers)
Other Changes
----------------------

View File

@ -305,12 +305,27 @@ abstract class CSVLoader extends ContentStreamLoader {
private void input_err(String msg, String[] line, int lineno) {
StringBuilder sb = new StringBuilder();
sb.append(errHeader+", line="+lineno + ","+msg+"\n\tvalues={");
for (String val: line) { sb.append("'"+val+"',"); }
sb.append(errHeader).append(", line=").append(lineno).append(",").append(msg).append("\n\tvalues={");
for (String val: line) {
sb.append("'").append(val).append("',"); }
sb.append('}');
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,sb.toString());
}
private void input_err(String msg, String[] lines, int lineNo, Throwable e) {
StringBuilder sb = new StringBuilder();
sb.append(errHeader).append(", line=").append(lineNo).append(",").append(msg).append("\n\tvalues={");
if (lines != null) {
for (String val : lines) {
sb.append("'").append(val).append("',");
}
} else {
sb.append("NO LINES AVAILABLE");
}
sb.append('}');
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,sb.toString(), e);
}
/** load the CSV input */
public void load(SolrQueryRequest req, SolrQueryResponse rsp, ContentStream stream) throws IOException {
errHeader = "CSVLoader: input=" + stream.getSourceInfo();
@ -341,7 +356,13 @@ abstract class CSVLoader extends ContentStreamLoader {
// read the rest of the CSV file
for(;;) {
int line = parser.getLineNumber(); // for error reporting in MT mode
String[] vals = parser.getLine();
String[] vals = null;
try {
vals = parser.getLine();
} catch (IOException e) {
//Catch the exception and rethrow it with more line information
input_err("can't read line: " + line, null, line, e);
}
if (vals==null) break;
if (vals.length != fields.length) {