Skip to content

fix(metadata set): return error when both --datasource-filepath and -datasource-ls are used#16049

Merged
sholderbach merged 5 commits intonushell:mainfrom
kumarUjjawal:refactor-command
Jul 2, 2025
Merged

fix(metadata set): return error when both --datasource-filepath and -datasource-ls are used#16049
sholderbach merged 5 commits intonushell:mainfrom
kumarUjjawal:refactor-command

Conversation

@kumarUjjawal
Copy link
Copy Markdown
Contributor

Description

This PR improves the metadata set command by returning a clear error when both --datasource-filepath and --datasource-ls flags are used together. These flags are meant to be mutually exclusive, and previously this conflicting usage was silently ignored.

User-Facing Changes

  • Users will now see an error message if they use both --datasource-filepath and --datasource-ls together in metadata set.

Tests + Formatting

  • Added test at crates/nu-command/tests/commands/debug/metadata_set.rs to verify the error behavior.
  • Ran cargo fmt --all -- --check
  • Ran cargo clippy --workspace -- -D warnings -D clippy::unwrap_used
  • Ran cargo test --workspace

After Submitting

N/A

Comment on lines +59 to +65
if has_input {
return Ok(Value::record(
extend_record_with_metadata(Record::new(), input.metadata().as_ref(), call.head),
call.head,
)
.into_pipeline_data());
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@132ikl does this part clash in logic with your change from #16014 (it doesn't overlap in the diff but early returns)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would this be the right approach?

         if has_input {
            let metadata = input.metadata();
            let val = input.into_value(call.head)?;
            return Ok(
                build_metadata_record_value(&val, metadata.as_ref(), call.head)
                    .into_pipeline_data(),
            );
        }

Copy link
Copy Markdown
Member

@132ikl 132ikl Jul 2, 2025

Choose a reason for hiding this comment

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

honestly, I don't think the early return is necessary at all, we're already handling the case where the argument is None in the big match. i added a suggestion down below

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also my bad i deleted my github comment because github was showing it twice but that deleted both versions of my comment apparently, lol

Comment on lines +46 to +65
let has_input = !matches!(input, PipelineData::Empty);

if let Some(arg_expr) = arg {
if has_input {
return Err(ShellError::IncompatibleParameters {
left_message: "pipeline input was provided".into(),
left_span: head,
right_message: "but a positional metadata expression was also given".into(),
right_span: arg_expr.span,
});
}
}

if has_input {
return Ok(Value::record(
extend_record_with_metadata(Record::new(), input.metadata().as_ref(), call.head),
call.head,
)
.into_pipeline_data());
}
Copy link
Copy Markdown
Member

@132ikl 132ikl Jul 2, 2025

Choose a reason for hiding this comment

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

Suggested change
let has_input = !matches!(input, PipelineData::Empty);
if let Some(arg_expr) = arg {
if has_input {
return Err(ShellError::IncompatibleParameters {
left_message: "pipeline input was provided".into(),
left_span: head,
right_message: "but a positional metadata expression was also given".into(),
right_span: arg_expr.span,
});
}
}
if has_input {
return Ok(Value::record(
extend_record_with_metadata(Record::new(), input.metadata().as_ref(), call.head),
call.head,
)
.into_pipeline_data());
}
if !matches!(input, PipelineData::Empty) {
if let Some(arg_expr) = arg {
return Err(ShellError::IncompatibleParameters {
left_message: "pipeline input was provided".into(),
left_span: head,
right_message: "but a positional metadata expression was also given".into(),
right_span: arg_expr.span,
});
}
}

Copy link
Copy Markdown
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

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

LGTM thanks for iterating @kumarUjjawal and thanks for the feedback @132ikl

@sholderbach sholderbach merged commit 118857a into nushell:main Jul 2, 2025
16 checks passed
@github-actions github-actions bot added this to the v0.106.0 milestone Jul 2, 2025
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.

3 participants