From 32b5d7ff6e7da5be6e48444fe73a0a8c3663b80e Mon Sep 17 00:00:00 2001 From: kwahlin Date: Wed, 8 Nov 2023 10:17:42 +0100 Subject: [PATCH 1/2] Terminate script immediately (with explicit exit code) on error --- .../src/main/groovy/datatool/WhelkTool.groovy | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/whelktool/src/main/groovy/datatool/WhelkTool.groovy b/whelktool/src/main/groovy/datatool/WhelkTool.groovy index f3543f2aee..d00b62baf2 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(2) + } log "Done!" } From f42d44f1a8361ba4155df8f7924839ddd33b41a4 Mon Sep 17 00:00:00 2001 From: kwahlin <72360110+kwahlin@users.noreply.github.com> Date: Wed, 8 Nov 2023 11:04:30 +0100 Subject: [PATCH 2/2] Use proper exit code Co-authored-by: Anders Jensen-Urstad --- whelktool/src/main/groovy/datatool/WhelkTool.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whelktool/src/main/groovy/datatool/WhelkTool.groovy b/whelktool/src/main/groovy/datatool/WhelkTool.groovy index d00b62baf2..224a796ebd 100644 --- a/whelktool/src/main/groovy/datatool/WhelkTool.groovy +++ b/whelktool/src/main/groovy/datatool/WhelkTool.groovy @@ -693,7 +693,7 @@ class WhelkTool { } if (errorDetected) { log "Script terminated due to an error, see $reportsDir/ERRORS.txt for more info" - System.exit(2) + System.exit(1) } log "Done!" }