Skip to content

Commit

Permalink
Fix script error text alignment (#4681)
Browse files Browse the repository at this point in the history

Signed-off-by: Mahesh Binzer-Panchal <mahesh.binzer-panchal@nbis.se>
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
Co-authored-by: Ben Sherman <bentshermann@gmail.com>
  • Loading branch information
2 people authored and pditommaso committed May 4, 2024
1 parent 653064f commit ea1cc2c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -750,26 +750,42 @@ 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()
final last = node.getLastLineNumber()
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')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1335,9 +1335,10 @@ class TaskProcessor {
else
message = err0(error.cause)

message.eachLine { line ->
result << ' ' << line << '\n'
}
result
.append(' ')
.append(message)
.append('\n')
.toString()
}
Expand Down

0 comments on commit ea1cc2c

Please sign in to comment.