diff --git a/crates/nu-command/src/generators/generate.rs b/crates/nu-command/src/generators/generate.rs index 9c61d0fa93..346de452ed 100644 --- a/crates/nu-command/src/generators/generate.rs +++ b/crates/nu-command/src/generators/generate.rs @@ -205,7 +205,7 @@ fn get_initial_state( msg: "Missing intial value".to_string(), span: Some(span), help: Some( - "Provide initial value in generate, or assigning default value to closure parameter" + "Providing argument to generate, or assigning default value to closure parameter" .to_string(), ), inner: vec![], diff --git a/crates/nu-command/tests/commands/generate.rs b/crates/nu-command/tests/commands/generate.rs index 284a3e3cb8..2fa0754993 100644 --- a/crates/nu-command/tests/commands/generate.rs +++ b/crates/nu-command/tests/commands/generate.rs @@ -132,3 +132,19 @@ fn generate_allow_default_parameter() { )); assert_eq!(actual.out, "[null, null, done]"); } + +#[test] +fn generate_raise_error_on_no_default_parameter_closure_and_init_val() { + let actual = nu!(pipeline( + r#" + generate {|x| + if $x == 3 { + {out: "done"} + } else { + {out: null, next: ($x + 1)} + } + } | to nuon + "# + )); + assert_eq!(actual.err, "The initial value is missing"); +}