Skip to content

Commit

Permalink
TIKA-4274: improve ExtractReaderException and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
THausherr committed Jul 7, 2024
1 parent 5167832 commit 1039898
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,21 @@ public List<Metadata> loadExtract(Path extractFile) throws ExtractReaderExceptio
try {
length = Files.size(extractFile);
} catch (IOException e) {
throw new ExtractReaderException(ExtractReaderException.TYPE.IO_EXCEPTION);
throw new ExtractReaderException(ExtractReaderException.TYPE.IO_EXCEPTION, e);
}

if (length == 0L) {
throw new ExtractReaderException(ExtractReaderException.TYPE.ZERO_BYTE_EXTRACT_FILE);
}

if (minExtractLength > IGNORE_LENGTH && length < minExtractLength) {
LOG.info("minExtractLength {} > IGNORE_LENGTH {} and length {} < minExtractLength {}",
minExtractLength, IGNORE_LENGTH, length, minExtractLength);
throw new ExtractReaderException(ExtractReaderException.TYPE.EXTRACT_FILE_TOO_SHORT);
}
if (maxExtractLength > IGNORE_LENGTH && length > maxExtractLength) {
LOG.info("maxExtractLength {} > IGNORE_LENGTH {} and length {} > maxExtractLength {}",
maxExtractLength, IGNORE_LENGTH, length, maxExtractLength);
throw new ExtractReaderException(ExtractReaderException.TYPE.EXTRACT_FILE_TOO_LONG);
}

Expand All @@ -148,7 +152,7 @@ public List<Metadata> loadExtract(Path extractFile) throws ExtractReaderExceptio
}
reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
} catch (IOException e) {
throw new ExtractReaderException(ExtractReaderException.TYPE.IO_EXCEPTION);
throw new ExtractReaderException(ExtractReaderException.TYPE.IO_EXCEPTION, e);
}

try {
Expand Down Expand Up @@ -177,7 +181,7 @@ public List<Metadata> loadExtract(Path extractFile) throws ExtractReaderExceptio
metadataList = generateListFromTextFile(reader, fileSuffixes);
}
} catch (IOException e) {
throw new ExtractReaderException(ExtractReaderException.TYPE.IO_EXCEPTION);
throw new ExtractReaderException(ExtractReaderException.TYPE.IO_EXCEPTION, e);
} finally {
IOUtils.closeQuietly(reader);
IOUtils.closeQuietly(is);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public class ExtractReaderException extends IOException {
private final TYPE type;

public ExtractReaderException(TYPE exceptionType) {
super(exceptionType.toString());
this.type = exceptionType;
}

public ExtractReaderException(TYPE exceptionType, Throwable t) {
super(exceptionType.toString(), t);
this.type = exceptionType;
}

Expand Down

0 comments on commit 1039898

Please sign in to comment.