fix(metadata set): return error when both --datasource-filepath and -datasource-ls are used#16049
Merged
sholderbach merged 5 commits intonushell:mainfrom Jul 2, 2025
Merged
Conversation
sholderbach
reviewed
Jun 26, 2025
sholderbach
reviewed
Jun 27, 2025
sholderbach
reviewed
Jun 29, 2025
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()); | ||
| } |
Member
Contributor
Author
There was a problem hiding this comment.
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(),
);
}
Member
There was a problem hiding this comment.
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
Member
There was a problem hiding this comment.
also my bad i deleted my github comment because github was showing it twice but that deleted both versions of my comment apparently, lol
132ikl
reviewed
Jul 2, 2025
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()); | ||
| } |
Member
There was a problem hiding this comment.
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, | |
| }); | |
| } | |
| } |
38e6f3c to
e915922
Compare
sholderbach
approved these changes
Jul 2, 2025
Member
sholderbach
left a comment
There was a problem hiding this comment.
LGTM thanks for iterating @kumarUjjawal and thanks for the feedback @132ikl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR improves the
metadata setcommand by returning a clear error when both--datasource-filepathand--datasource-lsflags are used together. These flags are meant to be mutually exclusive, and previously this conflicting usage was silently ignored.User-Facing Changes
--datasource-filepathand--datasource-lstogether inmetadata set.Tests + Formatting
crates/nu-command/tests/commands/debug/metadata_set.rsto verify the error behavior.cargo fmt --all -- --checkcargo clippy --workspace -- -D warnings -D clippy::unwrap_usedcargo test --workspaceAfter Submitting
N/A