Skip to content

Commit

Permalink
Fix get -i ignoring errors for only the first cellpath (nushell#11213)
Browse files Browse the repository at this point in the history
# Description
Fixes issue nushell#11212 where only the first cellpath supplied to `get -i` is
treated as optional, and the rest of the cell paths are treated as
non-optional.

# Tests
Added one test.
  • Loading branch information
IanManske authored and dmatos2012 committed Feb 20, 2024
1 parent 7c932ae commit 5bb6f03
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/nu-command/src/filters/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ If multiple cell paths are given, this will produce a list of values."#
) -> Result<PipelineData, ShellError> {
let span = call.head;
let mut cell_path: CellPath = call.req(engine_state, stack, 0)?;
let rest: Vec<CellPath> = call.rest(engine_state, stack, 1)?;
let mut rest: Vec<CellPath> = call.rest(engine_state, stack, 1)?;
let ignore_errors = call.has_flag("ignore-errors");
let sensitive = call.has_flag("sensitive");
let ctrlc = engine_state.ctrlc.clone();
let metadata = input.metadata();

if ignore_errors {
cell_path.make_optional();
for path in &mut rest {
path.make_optional();
}
}

if rest.is_empty() {
Expand Down
7 changes: 7 additions & 0 deletions crates/nu-command/tests/commands/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,10 @@ fn ignore_errors_works() {

assert_eq!(actual.out, "null");
}

#[test]
fn ignore_multiple() {
let actual = nu!(r#"[[a];[b]] | get -i c d | to nuon"#);

assert_eq!(actual.out, "[[null], [null]]");
}

0 comments on commit 5bb6f03

Please sign in to comment.