Repository: nushell/nushell
File: crates/nu-command/src/debug/metadata.rs (Rust)

Code before:
        call: &Call,
        input: PipelineData,
    ) -> Result<PipelineData, ShellError> {
        let arg = call.positional_nth(stack, 0);
        let head = call.head;

        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());
        }

        match arg {
            Some(Expression {
                expr: Expr::FullCellPath(full_cell_path),
                span,
                ..
            }) => {
                if full_cell_path.tail.is_empty() {
                    match &full_cell_path.head {
                        Expression {
                            expr: Expr::Var(var_id),
                            ..
                        } => {
                            let origin = stack.get_var_with_origin(*var_id, *span)?;
                            Ok(build_metadata_record_value(
                                &origin,
                                input.metadata().as_ref(),
                                head,
                            )
                            .into_pipeline_data())
                        }
                        _ => {
                            let val: Value = call.req(engine_state, stack, 0)?;
                            Ok(
                                build_metadata_record_value(&val, input.metadata().as_ref(), head)

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

Code after:
        call: &Call,
        input: PipelineData,
    ) -> Result<PipelineData, ShellError> {
        let arg = call.positional_nth(stack, 0);
        let head = call.head;

        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,
                });
            }
        }

        match arg {
            Some(Expression {
                expr: Expr::FullCellPath(full_cell_path),
                span,
                ..
            }) => {
                if full_cell_path.tail.is_empty() {
                    match &full_cell_path.head {
                        Expression {
                            expr: Expr::Var(var_id),
                            ..
                        } => {
                            let origin = stack.get_var_with_origin(*var_id, *span)?;
                            Ok(build_metadata_record_value(
                                &origin,
                                input.metadata().as_ref(),
                                head,
                            )
                            .into_pipeline_data())
                        }
                        _ => {
                            let val: Value = call.req(engine_state, stack, 0)?;
                            Ok(
                                build_metadata_record_value(&val, input.metadata().as_ref(), head)
                                    .into_pipeline_data(),
                            )
                        }
                    }
                } else {
                    let val: Value = call.req(engine_state, stack, 0)?;
                    Ok(
                        build_metadata_record_value(&val, input.metadata().as_ref(), head)
                            .into_pipeline_data(),
                    )