From 35609cb0edcbbb232d8d500bf524a097854dbf4a Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Mon, 30 Oct 2023 17:37:03 +0100 Subject: [PATCH] Improve error details for AbortOperationException This commit improves the error reporting for error reported via the AbortOperationException, so the script line location is added in the error message when available. Signed-off-by: Paolo Di Tommaso --- .../main/groovy/nextflow/cli/Launcher.groovy | 6 ++++-- .../groovy/nextflow/util/LoggerHelper.groovy | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/modules/nextflow/src/main/groovy/nextflow/cli/Launcher.groovy b/modules/nextflow/src/main/groovy/nextflow/cli/Launcher.groovy index 50e9d8df2a..be9458eaa2 100644 --- a/modules/nextflow/src/main/groovy/nextflow/cli/Launcher.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/cli/Launcher.groovy @@ -441,7 +441,8 @@ class Launcher { } catch ( AbortOperationException e ) { - System.err.println (e.message ?: "Unknown abort reason") + final msg = e.message ?: "Unknown abort reason" + System.err.println(LoggerHelper.formatErrMessage(msg, e)) System.exit(1) } catch( Throwable e ) { @@ -509,7 +510,8 @@ class Launcher { catch ( AbortOperationException e ) { def message = e.getMessage() - if( message ) System.err.println(message) + if( message ) + System.err.println(LoggerHelper.formatErrMessage(message,e)) log.debug ("Operation aborted", e.cause ?: e) return(1) } diff --git a/modules/nextflow/src/main/groovy/nextflow/util/LoggerHelper.groovy b/modules/nextflow/src/main/groovy/nextflow/util/LoggerHelper.groovy index 01f4e1af51..f78e7c8bd6 100644 --- a/modules/nextflow/src/main/groovy/nextflow/util/LoggerHelper.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/util/LoggerHelper.groovy @@ -55,8 +55,8 @@ import nextflow.Session import nextflow.cli.CliOptions import nextflow.cli.Launcher import nextflow.exception.AbortOperationException -import nextflow.exception.ProcessException import nextflow.exception.PlainExceptionMessage +import nextflow.exception.ProcessException import nextflow.exception.ScriptRuntimeException import nextflow.extension.OpCall import nextflow.file.FileHelper @@ -506,12 +506,15 @@ class LoggerHelper { // extra formatting if( error ) { - buffer.append(" -- Check script '${error[0]}' at line: ${error[1]} or see '${logFileName}' file for more details") + buffer.append(errorDetailsMsg(error)) } else if( logFileName && !quiet ) { buffer.append(" -- Check '${logFileName}' file for details") } + } + static private String errorDetailsMsg(List error) { + return " -- Check script '${error[0]}' at line: ${error[1]} or see '${logFileName}' file for more details" } @PackageScope @@ -572,6 +575,17 @@ class LoggerHelper { return msg } + static String formatErrMessage(String message, Throwable error) { + try { + final line = findErrorLine(error) + return line ? message + errorDetailsMsg(line) : message + } + catch (Throwable t) { + log.debug "Unable to determine script line for error: $error", t + return message + } + } + static List findErrorLine( Throwable e ) { return findErrorLine(e, ScriptMeta.allScriptNames()) }