From 7a728340de423341430fbc77298c99bbece9c3e5 Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Tue, 5 Sep 2023 22:21:30 +0800 Subject: [PATCH] return error when user break sleep by ctrl-c (#10234) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description Closes: #10218 I think this is `sleep`'s specific issue, it's because it always return a `Value::nothing` where it's interrupted by `ctrl-c`. To fix the issue, I'd propose to make it returns Err(ShellError) This is how it behaves: ```nushell ❯ sleep 5sec; echo "hello!" ^CError: nu::shell::sleep_breaked × Sleep is breaked. ❯ sleep 5sec; ^echo "hello!" ^CError: nu::shell::sleep_breaked × Sleep is breaked. ``` # User-Facing Changes None # Tests + Formatting # After Submitting --- crates/nu-command/src/platform/sleep.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/platform/sleep.rs b/crates/nu-command/src/platform/sleep.rs index 2877fc1bf7..dec8c0eabe 100644 --- a/crates/nu-command/src/platform/sleep.rs +++ b/crates/nu-command/src/platform/sleep.rs @@ -62,7 +62,9 @@ impl Command for Sleep { } if nu_utils::ctrl_c::was_pressed(ctrlc_ref) { - break; + return Err(ShellError::InterruptedByUser { + span: Some(call.head), + }); } }