-
Notifications
You must be signed in to change notification settings - Fork 630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix error text alignment #4681
Fix error text alignment #4681
Conversation
✅ Deploy Preview for nextflow-docs-staging canceled.
|
bf7fb5b
to
2992a92
Compare
Signed-off-by: Mahesh Binzer-Panchal <mahesh.binzer-panchal@nbis.se>
Signed-off-by: Mahesh Binzer-Panchal <mahesh.binzer-panchal@nbis.se>
2992a92
to
6e6be8c
Compare
Hi @mahesh-panchal thank you for taking the time to open this PR. The fix for the Error Cause looks spot on to me. On the other hand, I would like to inspect a bit more the other fix, on the Task Source. In fact, the current approach in the PR does not seem general (see example below). @bentsherman what do you think? A breaking example :
workflow {
TASK(Channel.of('a')).view()
}
process TASK {
input:
val letter
script:
assert letter.isUpperCase()
def puzzle = null
if ( puzzle ) {
println "Puzzled"
println "Double puzzled"
} else {
println "LGTM"
}
"""
echo $letter
"""
output:
stdout
}
|
My problem was I couldn't find where that was coming from quickly so if someone can point me in the right direction, I can amend the PR. |
The weird indentation comes from how the source code is extracted from the AST: nextflow/modules/nextflow/src/main/groovy/nextflow/ast/NextflowDSLImpl.groovy Lines 753 to 776 in 5c37fcc
The main AST transform wraps the script body in a BodyDef constructor and appends the source text as an argument. Each AST node includes the line and column range for the node, so it uses that to get the source text for each statement in the script body. The problem is that the text range doesn't include the indent before the statement, so if the statement spans multiple lines (e.g. an if-else statement), the first line is not indented. I think the ideal solution would be to adjust I will play around with this idea, and Mahesh you are more than welcome to do the same if you feel like delving into the AST 😄 |
ooh I can plug my developer docs: https://nextflow.io/docs/latest/developer/nextflow.ast.html |
I think what we can do is check if the AST node is preceded only by whitespace on the first line and if so, include it as the indent. I will try to make this work. Also need to handle this annoying edge case with |
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
Done! Works with both of your examples and also handles multi-statement lines, so the following code: script:
assert letter.isUpperCase() ; def puzzle = null Will be printed as: script:
assert letter.isUpperCase()
def puzzle = null @marcodelapierre if you're satisfied with this solution, let's merge it |
@bentsherman not quite there yet. 2 unit tests are failing in a quite significant way:
|
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
The failing tests are due to changing the workflow xform to extract the source of each statement instead of the entire body, which leaves out labels and whitespace. I just adjusted the tests but I don't like warping the workflow body source this much. I think I will go back to reading the entire workflow body and strip out the brackets some other way |
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
Thanks for pushing this over the finish line. |
Thanks for opening this PR! |
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>
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>
Fixes #4585
Input output
Using this toy:
I now get a properly formatted error:
Additional notes
task.source
seems to be formatted strangely suchstripIndent
doesn't work. As soon as it encounters indented code, all indentation is preserved. E.g.becomes: