While working on the new driver I ran into an inconsistency between how the process abstractions in
TSCBasic and swift-corelibs-foundation handle abnormal exits on Windows, and I was hoping to get some advice on the best way to solve it. Currently,
Foundation.Process under the hood when running on Windows, and exposes an ExitStatus API which excludes the
uncaughtSignal case that's present on Darwin/Linux. However, Foundation.Process is currently setting its
uncaughtSignal and clearing the top 2 bits of the exit code if it represents an abnormal exit according to the criteria here: https://github.com/apple/swift-corelibs-foundation/blob/f17b5a25bbc604126a8c6aca8b0b75c2e0291a6c/Sources/Foundation/Process.swift#L614. As a result, right now there's no way for TSCBasic.Process clients to check if an exit was abnormal, because the bits that would indicate an error have already been cleared, and the underlying
terminationReason isn't exposed.
I see two possible solutions to this problem:
Modify TSCBasic.Process.ExitStatus to include an
uncaughtSignalcase to match the one in
Foundation.Processand directly forward the
terminationReason. The terminology would be incorrect, but it's less invasive than the alternative.
Update Foundation so that it returns an unmodified exit code and doesn't misuse the
terminationReasonon Windows. This feels like it has the potential to break existing programs, but I'm really not sure .
Does anyone have an idea on which approach would be better, or if there's another alternative I should consider? Ideally I think we'd change the Foundation API to make more sense on other platforms, but I assume that's a nonstarter.