From f104b762a0922c939810de8eddfba2e28df271fa Mon Sep 17 00:00:00 2001 From: Torsten Stoeter Date: Wed, 11 Sep 2024 12:55:58 +0200 Subject: [PATCH] Handle also other possible exceptions when batch processing multiple files. If an exception occurs batch processing should continue, but now an exit code is returned when the program terminates, indicating there was an error. The logger level for messages was elevated to error was well. --- .../src/loci/formats/tools/ImageInfo.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/components/bio-formats-tools/src/loci/formats/tools/ImageInfo.java b/components/bio-formats-tools/src/loci/formats/tools/ImageInfo.java index a42c13b1d29..ecacf22ee82 100644 --- a/components/bio-formats-tools/src/loci/formats/tools/ImageInfo.java +++ b/components/bio-formats-tools/src/loci/formats/tools/ImageInfo.java @@ -77,7 +77,6 @@ import loci.formats.meta.MetadataStore; import loci.formats.services.OMEXMLService; import loci.formats.services.OMEXMLServiceImpl; -import loci.formats.UnknownFormatException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -1133,6 +1132,7 @@ private void printDimension(String dim, int size, int effectiveSize, public static void main(String[] args) throws Exception { DebugTools.enableLogging("INFO"); + int exitCode = 0; List argsList = Arrays.asList(args); int idx = argsList.indexOf("-"); @@ -1144,11 +1144,22 @@ public static void main(String[] args) throws Exception { newArgs[idx] = scanner.nextLine(); System.out.println("====% " + newArgs[idx]); try { - new ImageInfo().testRead(newArgs); + new ImageInfo().testRead(newArgs); } - catch (UnknownFormatException e) { - LOGGER.warn("Unknown file format: " + newArgs[idx]); - continue; + catch (FormatException e) { + LOGGER.error("Caught FormatException. " + e.getMessage()); + exitCode = 1; + continue; + } + catch (IOException e) { + LOGGER.error("Caught IOException. " + e.getMessage()); + exitCode = 1; + continue; + } + catch (ServiceException e) { + LOGGER.error("Caught ServiceException. " + e.getMessage()); + exitCode = 1; + continue; } } scanner.close(); @@ -1156,7 +1167,8 @@ public static void main(String[] args) throws Exception { else { if (!new ImageInfo().testRead(args)) System.exit(1); } - } + System.exit(exitCode); + } }