-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't tell return value of programs with staticExec #1994
Comments
Throw an exception if the return code is non-zero? |
It's not quite as simple as that (besides, exceptions should be used for unexpected, exceptional cases). Different platforms have different ideas on what a error return code is. |
There are three ways I've seen:
Personally, I think 2 would be the best, since platform-specific error codes might not matter; it could just have a |
2 is by far the hardest to implement and 1 affects backwards compatibility. What should be done is that the proc grows an "onErrorRaise= true" flag and then an OSError exception is raised. If set to false the empty string is returned instead. |
Wouldn't it make sense to force users to check the return code of the process? Therefore breaking backwards compatibility should be acceptable in this case. |
@dom96 Returning a tuple is quite hard to do in the VM though. |
@Araq Why is it hard? |
Now at least it produces "" instead of crashing, I think. |
That sounds like it will lead to some ambiguities. |
Bah, so a
Silently accepting output when the command fails is as bad as JavaScript's |
I'm with @dom96 and php ceo on this one. If i can't However, if this ship has sailed, so be it. At least we have const goods = gorgeEx("exit 69")
echo goods.output # ""
echo goods.exitCode # 69 My question is this: what's a guy gotta do to get a t-shirt around here? Should we be adding a I'm up for doing the work if you can tell me which direction you'd like. |
I still want what I asked for initially. But best wait for @Araq to give his okay, of course if you've got a PR ready it'll be harder to say "no" ;) |
IMO this is a breaking change that needs to happen before v1.0 so I'm adding this to the 1.0 milestone. |
Seriously? Ok then, do what you think is best. |
I had a look. With a handful of small changes to the gorge implementation we could die gloriously with a well placed However... My concern is, doing this would mean we won't be returning our tuple (output, exitcode). This would be the type of breaking change where we remove capabilities entirely (e.g. what if someone had a Seems like we could "configure" our way out of this (e.g. yet another param to govern whether we I do believe the default should blow up, but do y'all have any advice to do that along with keeping exitcode/output on the table? I'd love to see this feature through as I'm in way over my head and learning tonnes. |
Let the user decide if it needs to blow up. I'm using gorgeEx() in many .nimble files and looking at return values works just fine. |
… simplified implementation
… simplified implementation
This comment has been minimized.
This comment has been minimized.
The original issue ("Can't tell return value of programs with staticExec") has been solved by the addition of Since this is one of the issues marked with "v1.0 milestone", my question is: is the above enough and this can be closed, or is there some more (breaking) work that remains to be done (soon-ish)? |
Use |
Sorry to open this up again, but could we reflect this in the documentation a bit clearer? I was a bit confused by reading the docs because staticExec only mentions george as an alias but not georgeEx and there is nothing about return codes. But glad we have a solution. |
Using
staticExec
the return value of the executed program can't be checked. Even the manual's example ofgit rev-parse HEAD
can fail if you're not inside a git repo, which you can't catch nicely. I thinkstaticExec
should either return an empty string if the return value isn't 0, or have a way to get back the return value as well as stdout.The text was updated successfully, but these errors were encountered: