throw an error instead of a panic if no input is provided to inspect (#9259)

# Description

This is a small PR to fix Nu crashing when calling `inspect` with no
data piped in(#9255).


# User-Facing Changes

none.
This commit is contained in:
Tilen Gimpelj 2023-05-22 20:54:04 +02:00 committed by GitHub
parent a6e455efc3
commit 60041879f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View File

@ -34,6 +34,11 @@ impl Command for Inspect {
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
let input_metadata = input.metadata(); let input_metadata = input.metadata();
let input_val = input.into_value(call.head); let input_val = input.into_value(call.head);
if input_val.is_nothing() {
return Err(ShellError::PipelineEmpty {
dst_span: call.head,
});
}
let original_input = input_val.clone(); let original_input = input_val.clone();
let description = match input_val { let description = match input_val {
Value::CustomValue { ref val, .. } => val.value_string(), Value::CustomValue { ref val, .. } => val.value_string(),

View File

@ -0,0 +1,7 @@
use nu_test_support::nu;
#[test]
fn inspect_with_empty_pipeline() {
let actual = nu!("inspect");
assert!(actual.err.contains("no input value was piped in"));
}

View File

@ -37,6 +37,7 @@ mod headers;
mod help; mod help;
mod histogram; mod histogram;
mod insert; mod insert;
mod inspect;
mod into_filesize; mod into_filesize;
mod into_int; mod into_int;
mod join; mod join;