diff --git a/whelktool/src/main/groovy/datatool/WhelkTool.groovy b/whelktool/src/main/groovy/datatool/WhelkTool.groovy index f3543f2aee..224a796ebd 100644 --- a/whelktool/src/main/groovy/datatool/WhelkTool.groovy +++ b/whelktool/src/main/groovy/datatool/WhelkTool.groovy @@ -281,12 +281,7 @@ class WhelkTool { } private void select(Iterable selection, Closure process, - int batchSize = DEFAULT_BATCH_SIZE, boolean newItems = false) { - if (errorDetected) { - log "Error detected, refusing further processing." - return - } - + int batchSize = DEFAULT_BATCH_SIZE, boolean newItems = false) throws Exception { int batchCount = 0 Batch batch = new Batch(number: ++batchCount) @@ -303,6 +298,7 @@ class WhelkTool { err.printStackTrace errorLog errorLog.println "-" * 20 errorLog.flush() + errorDetected = err } } @@ -351,6 +347,11 @@ class WhelkTool { log() } loggerFuture?.cancel(true) + + if (errorDetected) { + log "Error detected, refusing further processing." + throw new Exception() + } } private def createExecutorService() { @@ -676,9 +677,12 @@ class WhelkTool { log() bindings = createMainBindings() - script.eval(bindings) - finish() + try { + script.eval(bindings) + } finally { + finish() + } } private void finish() { @@ -687,6 +691,10 @@ class WhelkTool { it.flush() it.close() } + if (errorDetected) { + log "Script terminated due to an error, see $reportsDir/ERRORS.txt for more info" + System.exit(1) + } log "Done!" }