Report the real syntax error for invalid script definitions - #7675
Merged
Merged
Conversation
When a process, workflow, agent, or output definition fails to parse, the parser falls back to parsing it as a statement (a method call with a closure), so the only error was a generic "Invalid <def> definition" highlighting the entire definition. Re-parse such statements as a script declaration so that the parser reports the actual syntax error at the offending token. Signed-off-by: Ben Sherman <bentshermann@gmail.com>
✅ Deploy Preview for nextflow-docs canceled.
|
jorgee
reviewed
Sep 29, 2026
Contributor
There was a problem hiding this comment.
The PR fixes most of the cases by providing a better error message; however, when there is a definition without body (process foo with no { ... }), it reports its error in the wrong place. The definition is parsed as a call, process(foo). The re-parse then fails on the first token after the statement, so the error lands outside the definition. For instance:
| Input | Before | After |
|---|---|---|
| process foo, a comment, then workflow { at line 7 | error on the process foo line | 7:1 Unexpected input: 'workflow' |
| process foo on the last line (line 6) | error on the process foo line | 7:1 Unexpected input: '' |
I have created #7712 with a suggestion for fixing this case.
The rest sounds good to me.
Member
Author
|
Thanks for the review. I closed your stacked PR because I'm wary of going too far down this rabbit trail. There will always be edge cases to improve but I don't want to bloat the parser too much. Let's revisit if we get user feedback about it |
jorgee
approved these changes
Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Close #7009
Close #7050
When a process, workflow, agent, or output definition fails to parse, the parser falls back to parsing it as a statement:
process foo { ... }is a command expression andworkflow { ... }is a method call with a closure-with-labels. So any syntax error inside a definition ended in the same generic error, highlighted over the whole definition:This PR re-parses such statements as a script declaration. The re-parse can't fall back to a statement, so the parser reports the actual syntax error at the offending token. No grammar changes, and valid scripts are only parsed once.
process 'MY-MODULE' {(#7009)1:1 Invalid process definition ...1:9 Unexpected input: ''MY-MODULE''sample1: Sample = ...in a workflow (#7050)Unexpected input: ':'on that lineoutput:beforeinput:input:take:aftermain:Unexpected input: ':'ontake:emmit:typoUnexpected input: ':'onemmit:The messages are still the terse
Unexpected input: ..., but now they point at the right place. One case is arguably worse: a definition missing a required section (e.g. an agent withoutprompt:) now reportsUnexpected input: '}'at the closing brace instead of hinting at section labels. Better wording belongs inDescriptiveErrorStrategy, as a follow-up.I also tried a semantic predicate on the top-level
statementalternative to block the fallback in the grammar. It doesn't work because ANTLR evaluates the predicate after rewinding the input, so the error is reported at theprocesskeyword again.