From 27fe1ca874fbafd79b9efac54ab1a1882c80c469 Mon Sep 17 00:00:00 2001 From: Grant Ingersoll Date: Tue, 25 Jan 2011 16:14:59 +0000 Subject: [PATCH] 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 --- solr/CHANGES.txt | 2 ++ .../solr/handler/CSVRequestHandler.java | 27 ++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) 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) {