Stream: beginners

Topic: CLI Error Message


view this post on Zulip Bryce Miller (May 07 2023 at 21:00):

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?

view this post on Zulip Brendan Hansknecht (May 08 2023 at 03:41):

Oh, that 's an interesting bug

view this post on Zulip Brendan Hansknecht (May 08 2023 at 03:43):

So here is what is happening. You can do roc helloWorld.roc to run the hello world app.

view this post on Zulip Brendan Hansknecht (May 08 2023 at 03:44):

If you do roc helloWorld.roc test, Roc doesn't know what to do with test. It just sees it as an invalid arg.

view this post on Zulip Brendan Hansknecht (May 08 2023 at 03:44):

So you get: Found argument 'test' which wasn't expected, or isn't valid in this context

view this post on Zulip Brendan Hansknecht (May 08 2023 at 03:45):

This is exactly what you are hitting.

view this post on Zulip Brendan Hansknecht (May 08 2023 at 03:45):

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.

view this post on Zulip Brendan Hansknecht (May 08 2023 at 03:45):

Also, we probably should allow roc helloWorld.roc test instead of requiring roc helloWorld.roc -- test

view this post on Zulip Brendan Hansknecht (May 08 2023 at 03:51):

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.

view this post on Zulip Brendan Hansknecht (May 08 2023 at 04:01):

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

view this post on Zulip Brendan Hansknecht (May 08 2023 at 04:05):

filed #5388

view this post on Zulip Bryce Miller (May 08 2023 at 05:31):

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.

view this post on Zulip Richard Feldman (May 08 2023 at 11:14):

Brendan Hansknecht said:

Also, we probably should allow roc helloWorld.roc test instead of requiring roc 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

view this post on Zulip Richard Feldman (May 08 2023 at 11:15):

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

view this post on Zulip Brendan Hansknecht (May 08 2023 at 13:34):

Yeah, clap 4 should fix that.


Last updated: Jul 05 2025 at 12:14 UTC