diff --git a/modules/nextflow/src/main/groovy/nextflow/ast/NextflowDSLImpl.groovy b/modules/nextflow/src/main/groovy/nextflow/ast/NextflowDSLImpl.groovy index 7396a5ab16..739c554f2d 100644 --- a/modules/nextflow/src/main/groovy/nextflow/ast/NextflowDSLImpl.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/ast/NextflowDSLImpl.groovy @@ -473,7 +473,7 @@ class NextflowDSLImpl implements ASTTransformation { } } // read the closure source - readSource(closure, source, unit, true) + readSource(closure, source, unit) final bodyClosure = closureX(null, block(scope, body)) final invokeBody = makeScriptWrapper(bodyClosure, source.toString(), 'workflow', unit) @@ -750,7 +750,29 @@ class NextflowDSLImpl implements ASTTransformation { * @param buffer * @param unit */ - private void readSource( ASTNode node, StringBuilder buffer, SourceUnit unit, stripBrackets=false ) { + private void readSource( Statement node, StringBuilder buffer, SourceUnit unit ) { + final colx = node.getColumnNumber() + final colz = node.getLastColumnNumber() + final first = node.getLineNumber() + final last = node.getLastLineNumber() + for( int i = first; i <= last; i++ ) { + final line = unit.source.getLine(i, null) + + // prepend first-line indent + if( i == first ) { + int k = 0 + while( k < line.size() && line[k] == ' ' ) + k++ + buffer.append( line.substring(0, k) ) + } + + final begin = (i == first) ? colx - 1 : 0 + final end = (i == last) ? colz - 1 : line.size() + buffer.append( line.substring(begin, end) ).append('\n') + } + } + + private void readSource( ClosureExpression node, StringBuilder buffer, SourceUnit unit ) { final colx = node.getColumnNumber() final colz = node.getLastColumnNumber() final first = node.getLineNumber() @@ -758,18 +780,12 @@ class NextflowDSLImpl implements ASTTransformation { for( int i=first; i<=last; i++ ) { def line = unit.source.getLine(i, null) if( i==last ) { - line = line.substring(0,colz-1) - if( stripBrackets ) { - line = line.replaceFirst(/}.*$/,'') - if( !line.trim() ) continue - } + line = line.substring(0,colz-1).replaceFirst(/}.*$/,'') + if( !line.trim() ) continue } if( i==first ) { - line = line.substring(colx-1) - if( stripBrackets ) { - line = line.replaceFirst(/^.*\{/,'').trim() - if( !line.trim() ) continue - } + line = line.substring(colx-1).replaceFirst(/^.*\{/,'').trim() + if( !line ) continue } buffer.append(line) .append('\n') } diff --git a/modules/nextflow/src/main/groovy/nextflow/processor/TaskProcessor.groovy b/modules/nextflow/src/main/groovy/nextflow/processor/TaskProcessor.groovy index 83a7707500..edc8ab6642 100644 --- a/modules/nextflow/src/main/groovy/nextflow/processor/TaskProcessor.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/processor/TaskProcessor.groovy @@ -1335,9 +1335,10 @@ class TaskProcessor { else message = err0(error.cause) + message.eachLine { line -> + result << ' ' << line << '\n' + } result - .append(' ') - .append(message) .append('\n') .toString() }