Skip to content
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

Closed
def- opened this issue Jan 22, 2015 · 20 comments
Closed

Can't tell return value of programs with staticExec #1994

def- opened this issue Jan 22, 2015 · 20 comments
Labels
Easy Feature VM see also `const` label Won't Fix

Comments

@def-
Copy link
Member

def- commented Jan 22, 2015

Using staticExec the return value of the executed program can't be checked. Even the manual's example of git rev-parse HEAD can fail if you're not inside a git repo, which you can't catch nicely. I think staticExec 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.

@hildjj
Copy link

hildjj commented Jan 26, 2015

Throw an exception if the return code is non-zero?

@Varriount
Copy link
Contributor

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.

@refi64
Copy link
Contributor

refi64 commented Jan 26, 2015

There are three ways I've seen:

  1. Return a tuple.
  2. Return a custom object. This is what Python does.
  3. Use var parameters. This seems very ugly to me.

Personally, I think 2 would be the best, since platform-specific error codes might not matter; it could just have a succeeded boolean attribute.

@Araq
Copy link
Member

Araq commented Jan 27, 2015

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.

@dom96
Copy link
Contributor

dom96 commented Jan 27, 2015

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.

@Araq
Copy link
Member

Araq commented Jan 27, 2015

@dom96 Returning a tuple is quite hard to do in the VM though.

@dom96
Copy link
Contributor

dom96 commented Jan 27, 2015

@Araq Why is it hard?

@Araq
Copy link
Member

Araq commented Mar 12, 2015

Now at least it produces "" instead of crashing, I think.

@dom96
Copy link
Contributor

dom96 commented Mar 12, 2015

That sounds like it will lead to some ambiguities.

@dom96
Copy link
Contributor

dom96 commented Sep 7, 2017

Bah, so a staticExecEx was added. This just caused a bug in Nimble:

~ » nimble -v
nimble v0.8.8 compiled at 2017-09-07 20:23:12
git hash: fatal: Not a git repository (or any of the parent directories): .git

Silently accepting output when the command fails is as bad as JavaScript's undefined. I vote to make this a breaking change and throw an exception when the command fails.

@dom96 dom96 reopened this Sep 7, 2017
@skellock
Copy link
Contributor

skellock commented Oct 2, 2018

I'm with @dom96 and php ceo on this one. If i can't staticExec, I want the build to burn to the ground.

However, if this ship has sailed, so be it. At least we have gorgeEx's exit code.

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 staticExecEx alias, documentation and call it a day? Should we check the exitCode and raise?

I'm up for doing the work if you can tell me which direction you'd like.

@dom96
Copy link
Contributor

dom96 commented Oct 4, 2018

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" ;)

@dom96
Copy link
Contributor

dom96 commented Oct 4, 2018

IMO this is a breaking change that needs to happen before v1.0 so I'm adding this to the 1.0 milestone.

@dom96 dom96 added this to the v1 milestone Oct 4, 2018
@Araq
Copy link
Member

Araq commented Oct 9, 2018

Seriously? Ok then, do what you think is best.

@skellock
Copy link
Contributor

skellock commented Oct 22, 2018

I had a look. With a handful of small changes to the gorge implementation we could die gloriously with a well placed localError().

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 gorgeEx call with another gorgeEx call as a fallback?).

Seems like we could "configure" our way out of this (e.g. yet another param to govern whether we localError or return the tuple), but I'm not really liking how my implementation is turning out.

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.

@genotrance
Copy link
Contributor

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.

timotheecour added a commit to timotheecour/Nim that referenced this issue Jan 17, 2019
timotheecour added a commit to timotheecour/Nim that referenced this issue Jan 17, 2019
@timotheecour

This comment has been minimized.

@narimiran
Copy link
Member

The original issue ("Can't tell return value of programs with staticExec") has been solved by the addition of gorgeEx (link), which returns a tuple with, I'm quoting, "the precious exit code". :)

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)?

@Araq Araq removed this from the v1 milestone Aug 16, 2019
@Araq Araq added the Won't Fix label Aug 16, 2019
@Araq
Copy link
Member

Araq commented Aug 16, 2019

Use gorgeEx or look at gorge's return value. Not worth breaking somebody's code at this point.

@Araq Araq closed this as completed Aug 16, 2019
@saemideluxe
Copy link
Contributor

saemideluxe commented Jan 11, 2023

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.
Also, Nim is great, thanks for all the people that work on it!
Also, I can write a PR for this in case PRs are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Easy Feature VM see also `const` label Won't Fix
Projects
None yet