mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Friendly error message for access beyond end (#6944)
Adds `ShellError::AccessEmptyContent`
This commit is contained in:
@ -316,7 +316,7 @@ impl NuDataFrame {
|
||||
let column = conversion::create_column(&series, row, row + 1, span)?;
|
||||
|
||||
if column.len() == 0 {
|
||||
Err(ShellError::AccessBeyondEnd(series.len(), span))
|
||||
Err(ShellError::AccessEmptyContent(span))
|
||||
} else {
|
||||
let value = column
|
||||
.into_iter()
|
||||
|
@ -138,6 +138,8 @@ fn update(
|
||||
for idx in 0..*val {
|
||||
if let Some(v) = input.next() {
|
||||
pre_elems.push(v);
|
||||
} else if idx == 0 {
|
||||
return Err(ShellError::AccessEmptyContent(*span));
|
||||
} else {
|
||||
return Err(ShellError::AccessBeyondEnd(idx - 1, *span));
|
||||
}
|
||||
|
@ -199,11 +199,17 @@ fn errors_fetching_by_index_out_of_bounds() {
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("Row number too large (max: 3)"),);
|
||||
assert!(actual.err.contains("Row number too large (max: 2)"),);
|
||||
assert!(actual.err.contains("too large"),);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_fetching_by_accessing_empty_list() {
|
||||
let actual = nu!(cwd: ".", pipeline(r#"[] | get 3"#));
|
||||
assert!(actual.err.contains("Row number too large (empty content)"),);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quoted_column_access() {
|
||||
let actual = nu!(
|
||||
|
Reference in New Issue
Block a user