mirror of
https://github.com/nushell/nushell.git
synced 2025-08-16 18:21:40 +02:00
fix inspect
and explore
panics on empty records (#13893)
# Description Fixes a couple panics: ``` > {} | inspect Error: x Main thread panicked. |-> at crates/nu-command/src/debug/inspect_table.rs:87:15 `-> attempt to divide by zero ``` ``` > {} | explore # see an empty column, press Down Error: x Main thread panicked. |-> at crates/nu-explore/src/views/cursor/mod.rs:39:9 `-> attempt to subtract with overflow ``` # User-Facing Changes `{} | inspect` now outputs an empty table: ``` ╭─────────────┬────────╮ │ description │ record │ ├─────────────┴────────┤ │ │ ├──────────────────────┤ ``` `{} | explore` opens the help menu. Both match the empty list behavior. # Tests I'm not sure how to test `explore`, as it waits for interaction.
This commit is contained in:
@ -92,8 +92,15 @@ pub fn collect_input(value: Value) -> Result<(Vec<String>, Vec<Vec<Value>>)> {
|
||||
let span = value.span();
|
||||
match value {
|
||||
Value::Record { val: record, .. } => {
|
||||
let (key, val) = record.into_owned().into_iter().unzip();
|
||||
Ok((key, vec![val]))
|
||||
let (key, val): (_, Vec<Value>) = record.into_owned().into_iter().unzip();
|
||||
|
||||
Ok((
|
||||
key,
|
||||
match val.is_empty() {
|
||||
true => vec![],
|
||||
false => vec![val],
|
||||
},
|
||||
))
|
||||
}
|
||||
Value::List { vals, .. } => {
|
||||
let mut columns = get_columns(&vals);
|
||||
|
Reference in New Issue
Block a user