From 6f9c81870084affb532a5edf600ac1d0e94880a8 Mon Sep 17 00:00:00 2001 From: bbimber Date: Thu, 4 Jan 2024 12:33:21 -0600 Subject: [PATCH] Improve error reporting for VcfToLuceneIndexer (#300) --- .../discvrseq/walkers/VcfToLuceneIndexer.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/github/discvrseq/walkers/VcfToLuceneIndexer.java b/src/main/java/com/github/discvrseq/walkers/VcfToLuceneIndexer.java index 4fbd5146..190ee03b 100644 --- a/src/main/java/com/github/discvrseq/walkers/VcfToLuceneIndexer.java +++ b/src/main/java/com/github/discvrseq/walkers/VcfToLuceneIndexer.java @@ -298,12 +298,12 @@ else if (line.getCountType() == VCFHeaderLineCount.INTEGER || line.getCountType( // should never reach this throw new GATKException("Attempted to parse a numeric value into something other than Double/Integer. This should never occur."); } catch (Exception e) { - possiblyReportBadValue(key, valueStr); + possiblyReportBadValue(e, key, valueStr); return null; } } else { - possiblyReportBadValue(key, valueStr); + possiblyReportBadValue(null, key, valueStr); return null; } } @@ -319,7 +319,7 @@ else if (clazz == Integer.class) { throw new GATKException("Attempted to parse a numeric value into something other than Double/Integer. This should never occur."); } catch (Exception e) { - possiblyReportBadValue(key, valueStr); + possiblyReportBadValue(e, key, valueStr); return null; } } @@ -327,8 +327,8 @@ else if (clazz == Integer.class) { private final Set keysWithErrors = new HashSet<>(); - private void possiblyReportBadValue(String key, Object fieldValue) { - String message = "Unable to parse numeric value for field: " + key + ", was: <" + fieldValue + ">"; + private void possiblyReportBadValue(@Nullable Exception e, String key, Object fieldValue) { + String message = "Unable to parse field: " + key + ", was: <" + fieldValue + ">. " + (e == null ? "" : e.getMessage()); if (stringency == ValidationStringency.STRICT) { throw new GATKException(message); } @@ -345,7 +345,7 @@ synchronized private void addFieldToDocument(Document doc, VCFHeaderLineType var stats.inspectValue(key, fieldValue); } catch (GATKException e) { - possiblyReportBadValue(key, fieldValue); + possiblyReportBadValue(e, key, fieldValue); } Collection values = fieldValue instanceof Collection ? (Collection) fieldValue : Collections.singleton(fieldValue); @@ -377,6 +377,7 @@ synchronized private void addFieldToDocument(Document doc, VCFHeaderLineType var } } case String -> doc.add(new TextField(key, String.valueOf(value), Field.Store.YES)); + default -> possiblyReportBadValue(new Exception("VCF header type was not expected: " + variantHeaderLineType.name()), key, value); } } catch (Exception e) {