From 37e93f71896c39bda93c868f61b37f675e01c3b7 Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Wed, 17 Jul 2024 07:55:44 +0800 Subject: [PATCH] make better error message --- crates/nu-command/src/generators/generate.rs | 27 ++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/crates/nu-command/src/generators/generate.rs b/crates/nu-command/src/generators/generate.rs index 210b21bc1e..c1d2d48f49 100644 --- a/crates/nu-command/src/generators/generate.rs +++ b/crates/nu-command/src/generators/generate.rs @@ -80,7 +80,7 @@ used as the next argument to the closure, otherwise generation stops. // A type of Option is used to represent state. Invocation // will stop on None. Using Option allows functions to output // one final value before stopping. - let mut state = Some(get_initial_state(initial, &block.signature)?); + let mut state = Some(get_initial_state(initial, &block.signature, call.head)?); // let mut state = Some(initial); let iter = std::iter::from_fn(move || { let arg = state.take()?; @@ -183,7 +183,11 @@ mod test { } } -fn get_initial_state(initial: Option, signature: &Signature) -> Result { +fn get_initial_state( + initial: Option, + signature: &Signature, + span: Span, +) -> Result { match initial { Some(v) => Ok(v), None => { @@ -193,19 +197,22 @@ fn get_initial_state(initial: Option, signature: &Signature) -> Result