Skip to content

Commit be8c311

Browse files
committed
report suppressed exceptions
1 parent a100155 commit be8c311

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexDatabase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,11 @@ private void indexParallel(String dir, IndexDownArgs args) throws IndexerExcepti
19081908
}
19091909
}
19101910

1911+
// TODO: debug/test only, REMOVE BEFORE INTEGRATION !!!
1912+
if (x.path.contains("a")) {
1913+
throw new OutOfMemoryError("fake OOM error");
1914+
}
1915+
19111916
progress.increment();
19121917
return x;
19131918
}

opengrok-indexer/src/main/java/org/opengrok/indexer/index/Indexer.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ public static int runMain(String[] argv) {
184184
Executor.registerErrorHandler();
185185
Set<String> subFilePaths = new HashSet<>(); // absolute paths
186186
Set<String> subFileArgs = new HashSet<>(); // relative to source root
187-
List<Throwable> throwableList = new ArrayList<>();
188187
int exitCode = 0;
189188

190189
try {
@@ -421,10 +420,22 @@ public static int runMain(String[] argv) {
421420
getInstance().sendToConfigHost(env, webappURI);
422421
}
423422
} catch (ParseException e) {
423+
// This is likely a problem with processing command line arguments, hence print the error to standard
424+
// error output.
424425
System.err.println("** " + e.getMessage());
425426
exitCode = 1;
426427
} catch (IndexerException ex) {
427-
throwableList.add(ex);
428+
// The exception(s) were logged already however it does not hurt to reiterate them
429+
// at the very end of indexing (sans the stack trace) since they might have been buried in the log.
430+
LOGGER.log(Level.SEVERE, "Indexer failed", ex);
431+
int i = 0;
432+
if (ex.getSuppressed().length > 0) {
433+
LOGGER.log(Level.INFO, "Suppressed exceptions ({0} in total):", ex.getSuppressed().length);
434+
for (Throwable throwable : ex.getSuppressed()) {
435+
LOGGER.log(Level.INFO, "{0}: {1}", new Object[]{++i, throwable.getLocalizedMessage()});
436+
}
437+
}
438+
exitCode = 1;
428439
} catch (Throwable e) {
429440
LOGGER.log(Level.SEVERE, "Unexpected Exception", e);
430441
System.err.println("Exception: " + e.getLocalizedMessage());
@@ -440,17 +451,7 @@ public static int runMain(String[] argv) {
440451
stats.report(LOGGER, "Indexer finished", "indexer.total");
441452
}
442453

443-
if (!throwableList.isEmpty()) {
444-
// The exception(s) were logged already however it does not hurt to reiterate them
445-
// at the very end of indexing (sans the stack trace) since they might have been buried in the log.
446-
LOGGER.log(Level.SEVERE, "Indexer finished with {0} exception{1}",
447-
new Object[]{throwableList.size(), throwableList.size() > 1 ? "s" : ""});
448-
int i = 0;
449-
for (Throwable throwable : throwableList) {
450-
LOGGER.log(Level.SEVERE, "{0}: {1}", new Object[]{++i, throwable.getLocalizedMessage()});
451-
}
452-
exitCode = 1;
453-
} else {
454+
if (exitCode == 0) {
454455
LOGGER.log(Level.INFO, "Indexer finished with success");
455456
}
456457

0 commit comments

Comments
 (0)