From 79da47023997d674d7f3939fd2062d457b2a7f3f Mon Sep 17 00:00:00 2001
From: WindSoilder <WindSoilder@outlook.com>
Date: Sat, 2 Jul 2022 10:06:36 +0800
Subject: [PATCH] simplify error make (#5883)

---
 .../src/core_commands/error_make.rs           | 48 +++++--------------
 1 file changed, 12 insertions(+), 36 deletions(-)

diff --git a/crates/nu-command/src/core_commands/error_make.rs b/crates/nu-command/src/core_commands/error_make.rs
index d43c2f158..64dd25101 100644
--- a/crates/nu-command/src/core_commands/error_make.rs
+++ b/crates/nu-command/src/core_commands/error_make.rs
@@ -2,8 +2,7 @@ use nu_engine::CallExt;
 use nu_protocol::ast::Call;
 use nu_protocol::engine::{Command, EngineState, Stack};
 use nu_protocol::{
-    Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape,
-    Value,
+    Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
 };
 
 #[derive(Clone)]
@@ -16,7 +15,7 @@ impl Command for ErrorMake {
 
     fn signature(&self) -> Signature {
         Signature::build("error make")
-            .optional("error_struct", SyntaxShape::Record, "the error to create")
+            .required("error_struct", SyntaxShape::Record, "the error to create")
             .category(Category::Core)
     }
 
@@ -33,43 +32,20 @@ impl Command for ErrorMake {
         engine_state: &EngineState,
         stack: &mut Stack,
         call: &Call,
-        input: PipelineData,
+        _input: PipelineData,
     ) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
         let span = call.head;
-        let ctrlc = engine_state.ctrlc.clone();
-        let arg: Option<Value> = call.opt(engine_state, stack, 0)?;
+        let arg: Value = call.req(engine_state, stack, 0)?;
 
-        if let Some(arg) = arg {
-            Ok(make_error(&arg, span)
-                .map(|err| Value::Error { error: err })
-                .unwrap_or_else(|| Value::Error {
-                    error: ShellError::GenericError(
-                        "Creating error value not supported.".into(),
-                        "unsupported error format".into(),
-                        Some(span),
-                        None,
-                        Vec::new(),
-                    ),
-                })
-                .into_pipeline_data())
-        } else {
-            input.map(
-                move |value| {
-                    make_error(&value, span)
-                        .map(|err| Value::Error { error: err })
-                        .unwrap_or_else(|| Value::Error {
-                            error: ShellError::GenericError(
-                                "Creating error value not supported.".into(),
-                                "unsupported error format".into(),
-                                Some(span),
-                                None,
-                                Vec::new(),
-                            ),
-                        })
-                },
-                ctrlc,
+        Err(make_error(&arg, span).unwrap_or_else(|| {
+            ShellError::GenericError(
+                "Creating error value not supported.".into(),
+                "unsupported error format".into(),
+                Some(span),
+                None,
+                Vec::new(),
             )
-        }
+        }))
     }
 
     fn examples(&self) -> Vec<Example> {