diff --git a/crates/nu-command/src/strings/str_/index_of.rs b/crates/nu-command/src/strings/str_/index_of.rs index 9287ece986..4c1d89d217 100644 --- a/crates/nu-command/src/strings/str_/index_of.rs +++ b/crates/nu-command/src/strings/str_/index_of.rs @@ -173,7 +173,7 @@ fn action( if s.get(start_index..end_index).is_none() { return Value::error( - ShellError::InvalidRange { + ShellError::OutOfBounds { left_flank: start_index.to_string(), right_flank: end_index.to_string(), span: range_span, diff --git a/crates/nu-protocol/src/shell_error.rs b/crates/nu-protocol/src/shell_error.rs index 02f18730b4..f640985060 100644 --- a/crates/nu-protocol/src/shell_error.rs +++ b/crates/nu-protocol/src/shell_error.rs @@ -1236,6 +1236,22 @@ This is an internal Nushell error, please file an issue https://github.com/nushe #[label = "cannot spread value"] span: Span, }, + + /// Out of bounds. + /// + /// ## Resolution + /// + /// Make sure the range is within the bounds of the input. + #[error( + "The selected range {left_flank}..{right_flank} is out of the bounds of the provided input" + )] + #[diagnostic(code(nu::shell::out_of_bounds))] + OutOfBounds { + left_flank: String, + right_flank: String, + #[label = "byte index is not a char boundary or is out of bounds of the input"] + span: Span, + }, } // TODO: Implement as From trait