Skip to content

Commit

Permalink
Improve error details for AbortOperationException
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
pditommaso committed Oct 30, 2023
1 parent b651dd3 commit 35609cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 4 additions & 2 deletions modules/nextflow/src/main/groovy/nextflow/cli/Launcher.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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)
}
Expand Down
18 changes: 16 additions & 2 deletions modules/nextflow/src/main/groovy/nextflow/util/LoggerHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String> error) {
return " -- Check script '${error[0]}' at line: ${error[1]} or see '${logFileName}' file for more details"
}

@PackageScope
Expand Down Expand Up @@ -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<String> findErrorLine( Throwable e ) {
return findErrorLine(e, ScriptMeta.allScriptNames())
}
Expand Down

0 comments on commit 35609cb

Please sign in to comment.