Skip to content

Report the real syntax error for invalid script definitions - #7675

Merged
bentsherman merged 2 commits into
masterfrom
invalid-def-syntax-error
Sep 29, 2026
Merged

bentsherman merged 2 commits into
masterfrom
invalid-def-syntax-error

Conversation

@bentsherman

@bentsherman bentsherman commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

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 and workflow { ... } 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:

Invalid process definition -- check for missing or out-of-order section labels

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.

Case Before After
process 'MY-MODULE' { (#7009) 1:1 Invalid process definition ... 1:9 Unexpected input: ''MY-MODULE''
sample1: Sample = ... in a workflow (#7050) whole workflow highlighted Unexpected input: ':' on that line
output: before input: whole process highlighted error at the misplaced input:
take: after main: whole workflow highlighted Unexpected input: ':' on take:
emmit: typo whole workflow highlighted Unexpected input: ':' on emmit:

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 without prompt:) now reports Unexpected input: '}' at the closing brace instead of hinting at section labels. Better wording belongs in DescriptiveErrorStrategy, as a follow-up.

I also tried a semantic predicate on the top-level statement alternative 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 the process keyword again.

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>
@bentsherman
bentsherman requested a review from a team as a code owner September 23, 2026 16:58
@netlify

netlify Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for nextflow-docs canceled.

Name Link
🔨 Latest commit 61b790b
🔍 Latest deploy log https://app.netlify.com/projects/nextflow-docs/deploys/6abc06d6d05c390008664e99

@jorgee jorgee left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bentsherman

Copy link
Copy Markdown
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

@bentsherman
bentsherman requested a review from jorgee September 29, 2026 15:16
@bentsherman
bentsherman merged commit e88b82c into master Sep 29, 2026
24 checks passed
@bentsherman
bentsherman deleted the invalid-def-syntax-error branch September 29, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type annotation without def fails to parse in workflow body Method with hyphens between quotes fails with in syntax parser v2

2 participants