some exec/arguments issues
- first,
exec.commandhas signature with variadic arguments:
command(name string, args ...string) command
but user functions cannot have variadic arguments, nor there is spread operator. So, I cannot write function like:
func myexec(cmd, args) {
c := exec.command(cmd, args) // type error: expected a string (list given)
exit_code := try(c.run, 1)
if exit_code != 0 {
print("COMMAND FAILED:", cmd, args)
print("STDOUT:", c.stdout)
print("STDERR:", c.stderr)
}
}
- second, it would be nice to print stacktrace when error has occured, because raw error message says nearly nothing
- third, it seems shebang shenninghans for
clipackage doesn't work for me.- first issue is that shebang passes arguments like so:
so, when shebang is$SHEBANG $SCRIPT $ARGS#!/usr/bin/env risor --it gives
If we fix shebang to/usr/bin/env: ‘risor --’: No such file or directory /usr/bin/env: use -[v]S to pass options in shebang lines#!/usr/bin/env -S risor --, following program is being executed:
which in turn calls/usr/bin/env -S risor -- script.risor $ARGS
BUT, as I understood,risor -- script.risor $ARGSrisorfor some reason requires script to be in formrisor script.risor -- $ARGSso actual behavior now is open risor repl. Though, for now this can be sidestepped with following shebang:#!/usr/bin/awk BEGIN{for (i=2; i<ARGC; i++) { subslice = subslice ARGV[i] " " }; system("risor "ARGV[1]" -- "subslice)}- second issue is that when we finally were able to call
risorcorrectly,os.argsgives array of strings from$ARGSwe passed along. BUT it should also include the script, such thatos.args() == ["./script.rasor", $ARGS...]. Because of that, I cannot passos.args()tocli.app.run()because the latter requires executable to be the first argument, which again can be sidestepped for now with.run(["vahui"] + os.args())
- one more issue is with running
exec: there is no way to catch exit code. The only way to not fail script and handle failed command for now goes like
c := exec.command(cmd, args)
exit_code := try(c.run, 1) // 1 is returned instead of actual non-zero code
if exit_code != 0 {
print("COMMAND FAILED:", cmd, args)
print("STDOUT:", c.stdout)
print("STDERR:", c.stderr)
}
such wrapper can be useful for e.g. printing failed command, printing it's stderr to get reason of failure, instead of just
exit status 1
which is not informative at all.
Thanks @rprtr258
I'll review all this, but I think a couple of these issues I have started to fix already. Others not yet.
Regarding the CLI and shebang lines, this branch has relevant improvements: https://github.com/risor-io/risor/compare/cli-fix?expand=1
The splat operator issue I came across as well and have started to implement here: https://github.com/risor-io/risor/compare/variadic-calls?expand=1
I think that branch needs a bit more work.
I agree the exec module has a couple deficiencies. I'll review your comments in more detail.