mirror of
https://github.com/nushell/nushell.git
synced 2025-04-29 15:44:28 +02:00
simplify error make (#5883)
This commit is contained in:
parent
37949e70e0
commit
79da470239
@ -2,8 +2,7 @@ use nu_engine::CallExt;
|
|||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape,
|
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||||
Value,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -16,7 +15,7 @@ impl Command for ErrorMake {
|
|||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("error make")
|
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)
|
.category(Category::Core)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,43 +32,20 @@ impl Command for ErrorMake {
|
|||||||
engine_state: &EngineState,
|
engine_state: &EngineState,
|
||||||
stack: &mut Stack,
|
stack: &mut Stack,
|
||||||
call: &Call,
|
call: &Call,
|
||||||
input: PipelineData,
|
_input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||||
let span = call.head;
|
let span = call.head;
|
||||||
let ctrlc = engine_state.ctrlc.clone();
|
let arg: Value = call.req(engine_state, stack, 0)?;
|
||||||
let arg: Option<Value> = call.opt(engine_state, stack, 0)?;
|
|
||||||
|
|
||||||
if let Some(arg) = arg {
|
Err(make_error(&arg, span).unwrap_or_else(|| {
|
||||||
Ok(make_error(&arg, span)
|
ShellError::GenericError(
|
||||||
.map(|err| Value::Error { error: err })
|
"Creating error value not supported.".into(),
|
||||||
.unwrap_or_else(|| Value::Error {
|
"unsupported error format".into(),
|
||||||
error: ShellError::GenericError(
|
Some(span),
|
||||||
"Creating error value not supported.".into(),
|
None,
|
||||||
"unsupported error format".into(),
|
Vec::new(),
|
||||||
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,
|
|
||||||
)
|
)
|
||||||
}
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
Loading…
Reference in New Issue
Block a user