-
Notifications
You must be signed in to change notification settings - Fork 291
isolate and handle unix error #3192
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
isolate and handle unix error #3192
Conversation
src/subprocess.rs
Outdated
| #[cfg(unix)] | ||
| pub(crate) fn new(status: std::process::ExitStatus) -> Self { | ||
| Self { | ||
| status: status.code().or_else(|| status.signal()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conflates a process exit code with an operating system signal number, and won't help with the original problem - it will just make it appear as if the subprocess has exited with a weird exit code.
A possible way forward is to make ExitStatusError an enum e.g.
pub enum ExitStatusError {
ExitCode(i32),
Signal(i32),
Unknown,
}
Then the message can report which case was in play, distinguishing the signal case from the process exit case.
(I am not sure if we can translate the (ETA from light googling this looks like it would be a pain but maybe someone knows better)i32 signal number into a meaningful-ish string - that would be great if we could.)
src/subprocess.rs
Outdated
| } | ||
|
|
||
| #[cfg(unix)] | ||
| #[cfg(windows)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Just in case someone wants to try compiling spin to wasm some day we could make things slightly easier for them. 🙂
| #[cfg(windows)] | |
| #[cfg(not(unix))] |
| match self { | ||
| Self::ExitCode(code) => *code, | ||
| Self::Signal(signal) => *signal, | ||
| Self::Unknown => 1, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to at least try to avoid confusion between exit codes and signals, even though its only slightly within our control here.
https://tldp.org/LDP/abs/html/exitcodes.html
128+n Fatal error signal "n"
255 Exit status out of range
| match self { | |
| Self::ExitCode(code) => *code, | |
| Self::Signal(signal) => *signal, | |
| Self::Unknown => 1, | |
| } | |
| // Exit code conventions: https://tldp.org/LDP/abs/html/exitcodes.html | |
| match self { | |
| Self::ExitCode(code) => *code, | |
| Self::Signal(signal) => 128 + *signal, | |
| Self::Unknown => 1, | |
| }.min(255) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sharing the docs, I've been curious to know why the unknown was initially set at 1. Makes more sense now!
src/subprocess.rs
Outdated
|
|
||
| match self { | ||
| Self::ExitCode(code) => writeln!(f, "{code}"), | ||
| Self::Signal(signal) => writeln!(f, "{signal}"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should expose the new detail we have:
| Self::Signal(signal) => writeln!(f, "{signal}"), | |
| Self::Signal(signal) => writeln!(f, "signal {signal}"), |
itowlson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I separated out the Zig CI stuff into a single-purpose PR, so please revert all GH workflow changes out of this one - thanks!
But the signals stuff looks great - thank you for improving this! Happy to approve once the CI stuff rolls back.
src/subprocess.rs
Outdated
|
|
||
| impl std::fmt::Display for ExitStatusError { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| let _ = write!(f, "subprocess exited with status: "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is extremely nitty but status: signal 7 reads a wee bit oddly to me. How would you feel about e.g. "subprocess exited with exit code 5", "subprocess exited with signal 7", "subprocess exited with unknown status"? Something like
let _ = write!(f, "subprocess exited with ");
match self {
Self::ExitCode(code) => write!(f, "exit code {code}"),
Self::Signal(signal) => write!(f, "signal {signal}"),
Self::ExitCode(code) => write!(f, "unknown status"),
}
Definitely not a blocker though and there may be others who prefer to leave as is!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is better. Would go for this, thanks!
acb4731 to
d27e6b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There shouldn't be any changes needed in the build.yml I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's only formatting. My IDE auto-formatted the file when I worked on it. The CI still works.
Should I revert the changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please. We mostly try to avoid PRs containing unrelated changes to different files, even formatting, because it makes the file history harder to follow.
Signed-off-by: Aminu 'Seun Joshua <[email protected]> - refactor: separate error code Signed-off-by: Aminu 'Seun Joshua <[email protected]> - wasm target included + update to error convention Signed-off-by: Aminu 'Seun Joshua <[email protected]> - fix: build workflow Signed-off-by: Aminu 'Seun Joshua <[email protected]> - fix: template issue with zig + docs Signed-off-by: Aminu 'Seun Joshua <[email protected]> - revert zig template Signed-off-by: Aminu 'Seun Joshua <[email protected]> - specify zig version for ci Signed-off-by: Aminu 'Seun Joshua <[email protected]> - revert workflow + re-word response Signed-off-by: Aminu 'Seun Joshua <[email protected]> - revert version edit Signed-off-by: Aminu 'Seun Joshua <[email protected]> - revert build workflow Signed-off-by: Aminu 'Seun Joshua <[email protected]>
2344e7e to
5342ced
Compare
itowlson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - looks good!
Aims to Fix #3161