Repository: nushell/nushell
File: crates/nu-command/src/platform/input/input_.rs (Rust)

Code before:
        let history_file_val: Option<String> =
            call.get_flag(engine_state, stack, "history-file")?;
        let max_history: usize = call
            .get_flag::<i64>(engine_state, stack, "max-history")?
            .map(|l| if l < 0 { 0 } else { l as usize })
            .unwrap_or(HISTORY_SIZE);

        let default_str = match (&prompt_str, &default_val) {
            (Some(_prompt), Some(val)) => format!("(default: {val}) "),
            _ => "".to_string(),
        };

        let history_entries = match input {
            PipelineData::Value(Value::List { vals, .. }, ..) => Some(vals),
            _ => None,
        };

        // If we either have history entries or history file, we create an history
        let history = match (history_entries.is_some(), history_file_val.is_some()) {
            (false, false) => None, // Neither are set, no need for history support
            _ => {
                let mut history = match history_file_val {
                    Some(file) => FileBackedHistory::with_file(max_history, file.into()),
                    None => FileBackedHistory::new(max_history),
                }
                .expect("Error creating history file");

                if let Some(vals) = history_entries {
                    vals.iter().for_each(|val| {
                        if let Value::String { val, .. } = val {
                            let _ = history.save(HistoryItem::from_command_line(val.clone()));
                        }
                    });
                }
                Some(history)
            }
        };

        let prompt = ReedlinePrompt {
            indicator: default_str,
            left_prompt: prompt_str.unwrap_or("".to_string()),
            right_prompt: "".to_string(),
        };

        let mut line_editor = Reedline::create();
        line_editor = line_editor.with_ansi_colors(false);
        line_editor = match history {
            Some(h) => line_editor.with_history(Box::new(h)),
            None => line_editor,
        };


Review comment (suggestion):
I think this can't be `expect`ed and needs user facing error handling with `ShellError`. Commands are not permitted to panic.

Code after:
        if !use_reedline {
            return self.legacy_input(engine_state, stack, call, input);
        }

        let prompt_str: Option<String> = call.opt(engine_state, stack, 0)?;
        let default_val: Option<String> = call.get_flag(engine_state, stack, "default")?;
        let history_file_val: Option<String> =
            call.get_flag(engine_state, stack, "history-file")?;
        let max_history: usize = call
            .get_flag::<i64>(engine_state, stack, "max-history")?
            .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}) "),
            _ => "".to_string(),
        };

        let history_entries = match input {
            PipelineData::Value(Value::List { vals, .. }, ..) => Some(vals),
            _ => None,
        };

        // If we either have history entries or history file, we create an history
        let history = match (history_entries.is_some(), history_file_val.is_some()) {
            (false, false) => None, // Neither are set, no need for history support
            _ => {
                let file_history = match history_file_val {
                    Some(file) => FileBackedHistory::with_file(max_history, file.into()),
                    None => FileBackedHistory::new(max_history),
                };
                let mut history = match file_history {
                    Ok(h) => h,
                    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,
                            });
                        }
                        _ => {