Repository navigation
fix(metadata set): return error when both --datasource-filepath and -datasource-ls are used - #16049
Merged
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, | |
| }); | |
| } | |
| } |
kumarUjjawal
force-pushed
the
refactor-command
branch
from
July 2, 2025 15:07
38e6f3c to
e915922
Compare
sholderbach
approved these changes
Jul 2, 2025
sholderbach
left a comment
Member
There was a problem hiding this comment.
LGTM thanks for iterating @kumarUjjawal and thanks for the feedback @132ikl
Closed
2 tasks done
fdncred
added a commit
that referenced
this pull request
Oct 16, 2026
…peline input instead of erroring (#19254) ## Description `metadata` with an argument fails when the call also has pipeline input: ```nushell [1] | each {|x| let s = (metadata $x).span; $s } # Error: nu::shell::incompatible_parameters # pipeline input was provided / but a positional metadata expression was also given ``` The user never piped anything into `metadata` here. The first statement of a block receives the block's input, which is intended (`"a" | do { let x = (str uppercase); $x }` returns `A`), so `metadata` gets the closure's input along with `$x` and refuses. The same check rejects `"a" | metadata $in`, because `$in` stores the input in the variable and still passes it to the call. The check came in with another PR. A command can't tell implicit block input from an explicit pipe at run time: both arrive as ordinary `PipelineData` in the same register. This PR removes the check. When `metadata` gets an argument, the result describes only that argument: a record with its `span`. The input and its pipeline metadata are ignored. Before #16049 the argument's span was merged with the input's pipeline metadata, which attached the input's metadata to an unrelated value: ```nushell open Cargo.toml | metadata 5 # {span: ..., source: ".../Cargo.toml"} <- input's source reported for the literal 5 ls | do { let m = (metadata $env.PWD); $m } # {span: ..., path_columns: [name], ...} <- ls's path columns reported for $env.PWD ``` `stor insert --data-record` and `stor update --update-record` had the same input-versus-argument check and failed the same way inside a block: ```nushell [{a: 1}] | each {|r| stor insert -t t -d $r } # Error: Pipeline and Flag both being used ``` ## User-facing changes (Release notes) - `metadata <expression>` no longer errors when the call also has pipeline input, such as the input a block's first statement receives (`[1] | each {|x| let s = (metadata $x).span; $s }`) or `"a" | metadata $in`. With an argument, `metadata` returns that argument's span and ignores the input; `metadata` without an argument still reports the input's pipeline metadata. - `stor insert --data-record` and `stor update --update-record` no longer error with "Pipeline and Flag both being used" when the call also has pipeline input. The flag's record takes precedence and the input is ignored. ## Additional notes - Since the input is ignored whenever an argument is given, an explicit pipe into these calls is now dropped without an error too (`ls | metadata $x`, `ls | stor insert -t t -d {a: 1}`). Erroring only on an explicit pipe would need the compiler to mark implicit block input, which no command can see today. - `metadata $in` returns only the span. The input's `path_columns`, `content_type` and custom keys are not included; use `metadata` without an argument for those. (`source` from `open` is already removed when the input is collected into `$in`.)
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