I just encountered this:
❯ roc foromat *
error: Found argument 'Ast.roc' which wasn't expected, or isn't valid in this context
I gave a bad command to roc, but the error message didn't reflect my mistake.
Reproduced on main branch.
Is this a known issue?
Oh, that 's an interesting bug
So here is what is happening. You can do roc helloWorld.roc
to run the hello world app.
If you do roc helloWorld.roc test
, Roc doesn't know what to do with test
. It just sees it as an invalid arg.
So you get: Found argument 'test' which wasn't expected, or isn't valid in this context
This is exactly what you are hitting.
In this case, I think we parse cli args in a kinda weird way and need to fix that up to give better error messages.
Also, we probably should allow roc helloWorld.roc test
instead of requiring roc helloWorld.roc -- test
So I guess fundamentally the parsing of roc foromat someOtherArg
. Parses as run roc
without a sub command. The file to run foromat
. someOtherArg
is invalid because roc
doesn't take any other args without a --
. Thus the error.
Looks like we need to update to clap 4 to fix requiring --
. Then you should instead get an error like file not found foromat
. Which isn't exactly better, but it may be clearer. Then we would need to update our file not found logic to check it the name is a type for a subcommand and that should enable us to get good error messages here
filed #5388
Hmm and you have to accept a file name in addition to a subcommand as the first arg so hashbangs work I guess. That’s tricky.
Brendan Hansknecht said:
Also, we probably should allow
roc helloWorld.roc test
instead of requiringroc helloWorld.roc -- test
yeah if I remember right, we started requiring --
at some point because e.g. roc run Foo.roc --optimize
would pass --optimize
to roc
, not to Foo.roc
but roc Foo.roc
(no subcommand) is reserved for #!/usr/bin/env roc
and therefore accepts no subcommands or flags, so everything after the filename can be (and should be) forwarded to the .roc
file
Yeah, clap 4 should fix that.
Last updated: Jul 05 2025 at 12:14 UTC