Skip to content

Commit

Permalink
Handle also other possible exceptions when batch processing multiple …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
tstoeter committed Sep 11, 2024
1 parent dd500c8 commit f104b76
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions components/bio-formats-tools/src/loci/formats/tools/ImageInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> argsList = Arrays.asList(args);
int idx = argsList.indexOf("-");

Expand All @@ -1144,19 +1144,31 @@ 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();
}
else {
if (!new ImageInfo().testRead(args)) System.exit(1);
}
}

System.exit(exitCode);
}
}

0 comments on commit f104b76

Please sign in to comment.