Swift and exit codes?

my goal here is to spawn a child process that has several different known failure modes, and obtain the failure type (if known) from the parent process. but exit codes are a bit of a minefield, and this needs to work consistently on both linux and macOS.

how should a child process communicate a failure mode to its parent?

1 Like

FWIW, Shwift AFAICT settled into a stand-off where it boxes the error code or signal for you.

See e.g., the error boxing
https://github.com/GeorgeLyon/Shwift/blob/d7be04898d094ddce6140cc6a2e9a83fc994b66d/Sources/Script/Script.swift#L166

and the underlying enum

https://github.com/GeorgeLyon/Shwift/blob/d7be04898d094ddce6140cc6a2e9a83fc994b66d/Sources/Shwift/Process.swift#L316

2 Likes

i may be misreading the code, but as far as i can understand, it is just boxing the error code it observes from the child process’s exit; it doesn’t have any capability of namespacing application-defined exit codes. the application running in the child process would need to choose an error encoding that does not overlap with anything else, and that encoding would need to be portable across two platforms.

an alternative that would not suffer from this problem might be as simple as “write the application’s exit code to a text file that contains a single integer in a location specified by the caller”. but that seemed a little silly.