Skip to content

Conversation

@seun-ja
Copy link
Contributor

@seun-ja seun-ja commented Jul 11, 2025

Aims to Fix #3161

#[cfg(unix)]
pub(crate) fn new(status: std::process::ExitStatus) -> Self {
Self {
status: status.code().or_else(|| status.signal()),
Copy link
Collaborator

@itowlson itowlson Jul 11, 2025

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 i32 signal number into a meaningful-ish string - that would be great if we could.) (ETA from light googling this looks like it would be a pain but maybe someone knows better)

}

#[cfg(unix)]
#[cfg(windows)]
Copy link
Collaborator

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. 🙂

Suggested change
#[cfg(windows)]
#[cfg(not(unix))]

Comment on lines 37 to 44
match self {
Self::ExitCode(code) => *code,
Self::Signal(signal) => *signal,
Self::Unknown => 1,
}
Copy link
Collaborator

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

Suggested change
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)

Copy link
Contributor Author

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!


match self {
Self::ExitCode(code) => writeln!(f, "{code}"),
Self::Signal(signal) => writeln!(f, "{signal}"),
Copy link
Collaborator

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:

Suggested change
Self::Signal(signal) => writeln!(f, "{signal}"),
Self::Signal(signal) => writeln!(f, "signal {signal}"),

Copy link
Collaborator

@itowlson itowlson left a 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.


impl std::fmt::Display for ExitStatusError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let _ = write!(f, "subprocess exited with status: ");
Copy link
Collaborator

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!

Copy link
Contributor Author

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!

@seun-ja seun-ja force-pushed the improve-error-messages-when-trigger-subprocess-killed-by-signal branch from acb4731 to d27e6b6 Compare July 13, 2025 22:49
@seun-ja seun-ja requested a review from itowlson July 13, 2025 22:52
Copy link
Collaborator

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?

Copy link
Contributor Author

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?

Copy link
Collaborator

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]>
@seun-ja seun-ja force-pushed the improve-error-messages-when-trigger-subprocess-killed-by-signal branch from 2344e7e to 5342ced Compare July 13, 2025 23:20
@seun-ja seun-ja requested a review from itowlson July 13, 2025 23:49
Copy link
Collaborator

@itowlson itowlson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - looks good!

@itowlson itowlson merged commit 792b355 into spinframework:main Jul 14, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error messages when trigger subprocess killed by signal

3 participants