Catch/log exceptions in the importers a bit more carefully.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@2215 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2011-08-22 21:47:15 +00:00
parent f023b922e1
commit 4113a10b5b
4 changed files with 41 additions and 23 deletions

View File

@ -52,6 +52,8 @@ import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.refine.ProjectMetadata; import com.google.refine.ProjectMetadata;
import com.google.refine.importing.ImportingJob; import com.google.refine.importing.ImportingJob;
@ -64,6 +66,8 @@ import com.google.refine.model.ReconCandidate;
import com.google.refine.util.JSONUtilities; import com.google.refine.util.JSONUtilities;
public class ExcelImporter extends TabularImportingParserBase { public class ExcelImporter extends TabularImportingParserBase {
static final Logger logger = LoggerFactory.getLogger(ExcelImporter.class);
public ExcelImporter() { public ExcelImporter() {
super(true); super(true);
} }
@ -110,7 +114,7 @@ public class ExcelImporter extends TabularImportingParserBase {
} }
} }
} catch (IOException e) { } catch (IOException e) {
// Ignore logger.error("Error generating parser UI initialization data for Excel file", e);
} }
return options; return options;

View File

@ -61,6 +61,8 @@ import com.google.refine.model.Project;
import com.google.refine.util.JSONUtilities; import com.google.refine.util.JSONUtilities;
public class JsonImporter extends TreeImportingParserBase { public class JsonImporter extends TreeImportingParserBase {
static final Logger logger = LoggerFactory.getLogger(JsonImporter.class);
public JsonImporter() { public JsonImporter() {
super(false); super(false);
} }
@ -93,7 +95,7 @@ public class JsonImporter extends TreeImportingParserBase {
is.close(); is.close();
} }
} catch (IOException e) { } catch (IOException e) {
// Ignore logger.error("Error generating parser UI initialization data for JSON file", e);
} }
} }

View File

@ -7,6 +7,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.refine.ProjectMetadata; import com.google.refine.ProjectMetadata;
import com.google.refine.importing.ImportingJob; import com.google.refine.importing.ImportingJob;
@ -14,6 +16,8 @@ import com.google.refine.model.Project;
import com.google.refine.util.JSONUtilities; import com.google.refine.util.JSONUtilities;
public class LineBasedImporter extends TabularImportingParserBase { public class LineBasedImporter extends TabularImportingParserBase {
static final Logger logger = LoggerFactory.getLogger(LineBasedImporter.class);
public LineBasedImporter() { public LineBasedImporter() {
super(false); super(false);
} }
@ -66,7 +70,7 @@ public class LineBasedImporter extends TabularImportingParserBase {
skip--; skip--;
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error("Error reading line-based file", e);
} }
JSONUtilities.safePut(options, "ignoreLines", -1); JSONUtilities.safePut(options, "ignoreLines", -1);

View File

@ -47,6 +47,8 @@ import javax.xml.stream.XMLStreamReader;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.refine.ProjectMetadata; import com.google.refine.ProjectMetadata;
import com.google.refine.importers.tree.ImportColumnGroup; import com.google.refine.importers.tree.ImportColumnGroup;
@ -58,6 +60,8 @@ import com.google.refine.model.Project;
import com.google.refine.util.JSONUtilities; import com.google.refine.util.JSONUtilities;
public class XmlImporter extends TreeImportingParserBase { public class XmlImporter extends TreeImportingParserBase {
static final Logger logger = LoggerFactory.getLogger(XmlImporter.class);
public XmlImporter() { public XmlImporter() {
super(true); super(true);
} }
@ -94,20 +98,20 @@ public class XmlImporter extends TreeImportingParserBase {
// ignore everything else // ignore everything else
} }
} }
} catch (XMLStreamException e) {
logger.warn("Error generating parser UI initialization data for XML file", e);
} finally { } finally {
is.close(); is.close();
} }
} }
} catch (XMLStreamException e) {
// Ignore
} catch (IOException e) { } catch (IOException e) {
// Ignore logger.error("Error generating parser UI initialization data for XML file", e);
} }
return options; return options;
} }
final static private JSONObject descendElement(XMLStreamReader parser, PreviewParsingState state) throws XMLStreamException { final static private JSONObject descendElement(XMLStreamReader parser, PreviewParsingState state) {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
{ {
String name = parser.getLocalName(); String name = parser.getLocalName();
@ -154,6 +158,7 @@ public class XmlImporter extends TreeImportingParserBase {
} }
JSONArray children = new JSONArray(); JSONArray children = new JSONArray();
try {
while (parser.hasNext() && state.tokenCount < PREVIEW_PARSING_LIMIT) { while (parser.hasNext() && state.tokenCount < PREVIEW_PARSING_LIMIT) {
int tokenType = parser.next(); int tokenType = parser.next();
state.tokenCount++; state.tokenCount++;
@ -174,6 +179,9 @@ public class XmlImporter extends TreeImportingParserBase {
// ignore everything else // ignore everything else
} }
} }
} catch (XMLStreamException e) {
logger.error("Error generating parser UI initialization data for XML file", e);
}
if (children.length() > 0) { if (children.length() > 0) {
JSONUtilities.safePut(result, "c", children); JSONUtilities.safePut(result, "c", children);