Skip to content

Add non-global ways to set debug and pipefail modes #85

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

Merged
merged 2 commits into from
Aug 3, 2025

Conversation

delan
Copy link
Contributor

@delan delan commented Aug 3, 2025

this is the second of two patches aimed at addressing thread safety issues. set_debug() and set_pipefail() change the debug and pipefail settings globally, which makes it impossible to reliably run commands with different settings in different threads. in single-threaded programs, this doesn’t really matter, so they are certainly still useful.

this patch adds ScopedDebug and ScopedPipefail, which override the global debug and pipefail settings, in the current thread only, until they go out of scope. calling set(new_value) changes the setting to Some(new_value), giving you a Self(old_value) that when dropped, restores the value to old_value.

i’ve also split the ignore and pipefail tests into their own test function test_ignore_and_pipefail(), using ScopedPipefail so they can run in parallel with the other tests in test_pipe().

@@ -108,6 +108,7 @@ fn test_vars_in_str3() {
}

#[test]
// FIXME: doctests have no effect here, and we need to split these into one test per error
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the notes, yeah I it is a known issue and I was just manually testing them previously.

Copy link
Collaborator

@tao-guo tao-guo left a comment

Choose a reason for hiding this comment

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

LGTM

///
/// Each override restores the previous value when dropped, so they can be nested.
/// Since overrides are thread-local, these values can’t be sent across threads.
// PhantomData field is equivalent to `impl !Send for Self {}`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the detailed docs!

@tao-guo tao-guo merged commit 269c357 into rust-shell-script:master Aug 3, 2025
1 check passed
@delan delan deleted the non-global-debug-pipefail branch August 3, 2025 15:10
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.

2 participants