swift-lang / swift-t

Swift/T: High Performance Parallel Scripting Language
http://swift-lang.org/Swift-T
Apache License 2.0
53 stars 22 forks source link

Exit code of 'app' functions not exposed/programmatic error handling hard #172

Closed u-u-h closed 5 years ago

u-u-h commented 5 years ago

When using an app function where the command indicates errors using a nonzero exit code the wrapping logic captures an error message, and I get a stack trace, but not the actual error code. When wrapping a simple utility function (say: curl(1)) the calling code may want to programmatically handle the exit code and not declare it complete program failure (e.g., an array or URLs get fetched in parallel; some may fail, we're only interested in the successful ones and the failure code).

I know I could write a full TCL wrapper with try ... block, but it seems to be a common pattern for app functions. Adding an @exitcode argument (like @stdout) seems like a clean way to express things in a backward-compatible fashion. Implementation requires touching a few more places in the turbine code base than I'd like to, so I don't have a patch yet.

j-woz commented 5 years ago

The best practice with Swift/T is to use an app function to call a shell script, then handle any errors in the shell script. Or put the exit code in a file where you can read() it later from Swift/T, but always exit 0 as far as Swift/T is concerned.

The other thing you could try is the system() and system1() functions: http://swift-lang.github.io/swift-t/guide.html#stdlib_system

j-woz commented 5 years ago

Did you get this working as intended?

u-u-h commented 5 years ago

It is on my todo list for late this year. Current plan is to implement something and post a pull request here.

j-woz commented 5 years ago

Ok, feel free to re-open this.