From 75e5cc42cec3155b27285f9d929da3521e2d08a4 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Thu, 17 Apr 2025 16:59:25 -0600 Subject: [PATCH] feat: map IOError to shell errors --- .../nu-command/src/platform/input/input_.rs | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/crates/nu-command/src/platform/input/input_.rs b/crates/nu-command/src/platform/input/input_.rs index 9a6f466f03..b23ec993fe 100644 --- a/crates/nu-command/src/platform/input/input_.rs +++ b/crates/nu-command/src/platform/input/input_.rs @@ -95,6 +95,7 @@ impl Command for Input { .map(|l| if l < 0 { 0 } else { l as usize }) .unwrap_or(HISTORY_SIZE); let max_history_span = call.get_flag_span(stack, "max-history"); + let history_file_span = call.get_flag_span(stack, "history-file"); let default_str = match (&prompt_str, &default_val) { (Some(_prompt), Some(val)) => format!("(default: {val}) "), @@ -116,13 +117,29 @@ impl Command for Input { }; let mut history = match file_history { Ok(h) => h, - Err(_e) => { - return Err(ShellError::IncorrectValue { - msg: "invalid max_history size".to_string(), - val_span: max_history_span.expect("max-history should be set"), - call_span: call.head, - }); - } + Err(e) => match e.0 { + reedline::ReedlineErrorVariants::IOError(err) => { + return Err(ShellError::IncorrectValue { + msg: err.to_string(), + val_span: history_file_span.expect("history-file should be set"), + call_span: call.head, + }); + } + reedline::ReedlineErrorVariants::OtherHistoryError(msg) => { + return Err(ShellError::IncorrectValue { + msg: msg.to_string(), + val_span: max_history_span.expect("max-history should be set"), + call_span: call.head, + }); + } + _ => { + return Err(ShellError::IncorrectValue { + msg: "unable to create history".to_string(), + val_span: call.head, + call_span: call.head, + }); + } + }, }; if let Some(vals) = history_entries {