diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 4aa8fac6833..e4cc0d2eb93 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -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 ---------------------- diff --git a/solr/src/java/org/apache/solr/handler/CSVRequestHandler.java b/solr/src/java/org/apache/solr/handler/CSVRequestHandler.java index 823b4502017..4a67d9ab909 100755 --- a/solr/src/java/org/apache/solr/handler/CSVRequestHandler.java +++ b/solr/src/java/org/apache/solr/handler/CSVRequestHandler.java @@ -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) {