Browse Source

check history file exist if not create it (#2245)

This Pull Request fixes/closes #2223.

It changes the following:

- Check the .boa_history file, if it is not exist then create the file before load history function to prevent the crash
pull/2249/head
udhaykumarbala 2 years ago
parent
commit
861b9a142b
  1. 8
      boa_cli/src/main.rs

8
boa_cli/src/main.rs

@ -63,7 +63,7 @@ use boa_engine::{syntax::ast::node::StatementList, Context};
use clap::{ArgEnum, Parser};
use colored::{Color, Colorize};
use rustyline::{config::Config, error::ReadlineError, EditMode, Editor};
use std::{fs::read, io, path::PathBuf};
use std::{fs::read, fs::OpenOptions, io, path::PathBuf};
mod helper;
#[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))]
@ -215,6 +215,12 @@ pub fn main() -> Result<(), io::Error> {
let mut editor =
Editor::with_config(config).map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
// Check if the history file exists. If it does, create it.
OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open(CLI_HISTORY)?;
editor.load_history(CLI_HISTORY).map_err(|err| match err {
ReadlineError::Io(e) => e,
e => io::Error::new(io::ErrorKind::Other, e),

Loading…
Cancel
Save