Skip to content
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

Add Process::Status#description #15468

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

straight-shoota
Copy link
Member

In the compiler we have a neat feature that shows a human readable description when a process process exited with an abnormal status.
This patch moves this as a gernal tool into stdlib as Process::Status#description.

The implementation is split into two parts:

  • Process::ExitReason#description provides the static description for most exit reasons
  • Process::Status#description enhances that description with details about the termination signal when it's a signal exit without further specification.

@straight-shoota straight-shoota force-pushed the feat/process-exit_reason-message branch from fe444fa to ee86ce6 Compare February 13, 2025 14:27
Comment on lines 414 to 424
description = exit_reason.description

if description.same?(SIGNAL_REASON_DESCRIPTION) && (signal = exit_signal?)
if signal.kill?
"Process was killed"
else
"Process received and didn't handle signal #{signal}"
end
else
description
end
Copy link
Contributor

@ysbaddaden ysbaddaden Feb 20, 2025

Choose a reason for hiding this comment

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

Suggestion: maybe we can directly ask exit_reason? We'd also have no need for the SIGNAL_REASON_DESCRIPTION constant.

Suggested change
description = exit_reason.description
if description.same?(SIGNAL_REASON_DESCRIPTION) && (signal = exit_signal?)
if signal.kill?
"Process was killed"
else
"Process received and didn't handle signal #{signal}"
end
else
description
end
if exit_reason.signal? && (signal = exit_signal?)
if signal.kill?
"Process was killed"
else
"Process received and didn't handle signal #{signal}"
end
else
exit_reason.description
end

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah. That makes me realize that the signal.kill? branch can never be reached here. This needs a bit of a different control flow.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or maybe we just leave the message for Signal::Kill as is: Process terminated abnormally instead of a specialized Process was killed.

Related: #15268

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to have, but if it's complex to convey, let's skip 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's super easy. Just adding another branch with exit_signal?.try(&.kill?).
I'm just wondering if it makes sense to have a different message just for Signal::KILL when it is otherwise treated the same as ABORT and QUIT.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say it's worth distinguishing these two cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably not. Process received and didn't handle signal KILL is explicit enough.

Copy link
Member Author

@straight-shoota straight-shoota Feb 20, 2025

Choose a reason for hiding this comment

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

The default description fo Signal::KILL is ExitReason::Aborted.description which is Process terminated abnormally.
This is the current state of this PR. See specs.

Comment on lines +411 to +412
# process.wait.description
# # => "Process received and didn't handle signal TERM (15)"
Copy link
Contributor

Choose a reason for hiding this comment

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

That IMO would make it clearer:

Suggested change
# process.wait.description
# # => "Process received and didn't handle signal TERM (15)"
# process.wait.description # => "Process received and didn't handle signal TERM (15)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants