diff options
author | Daniel Buckmaster <daniel@crabmusket.net> | 2019-08-08 21:25:39 +1000 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-08-08 07:25:39 -0400 |
commit | 520bdb6c31dd08b6f4e52de5116fd23d6d57fdda (patch) | |
tree | 1214cfdfb2cc032ee729f26f3738f7bda7e186f4 /cli/repl.rs | |
parent | e438ac2c74c823882dc9c9ecde2a9e9ed7bcfb4b (diff) |
Fix repl crash when deno dir doesn't exist (#2727)
Diffstat (limited to 'cli/repl.rs')
-rw-r--r-- | cli/repl.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/cli/repl.rs b/cli/repl.rs index 7e72b9b10..0cac6c4ea 100644 --- a/cli/repl.rs +++ b/cli/repl.rs @@ -76,6 +76,14 @@ impl Repl { } fn save_history(&mut self) -> Result<(), ErrBox> { + if !self.history_dir_exists() { + eprintln!( + "Unable to save REPL history: {:?} directory does not exist", + self.history_file + ); + return Ok(()); + } + self .editor .save_history(&self.history_file.to_str().unwrap()) @@ -86,6 +94,14 @@ impl Repl { }) } + fn history_dir_exists(&self) -> bool { + self + .history_file + .parent() + .map(|ref p| p.exists()) + .unwrap_or(false) + } + pub fn readline(&mut self, prompt: &str) -> Result<String, ErrBox> { self .editor |