Skip to content
Snippets Groups Projects
Commit 4674938a authored by Dmitry Rodionov's avatar Dmitry Rodionov
Browse files

fix: do not fail entire console on history load/save failures

parent 1854b10f
No related branches found
No related tags found
1 merge request!821fix: py tests were not run because of gitlab treating command as a comment
...@@ -103,7 +103,9 @@ impl Console { ...@@ -103,7 +103,9 @@ impl Console {
.unwrap_or_default() .unwrap_or_default()
.join(Path::new(Self::HISTORY_FILE_NAME)); .join(Path::new(Self::HISTORY_FILE_NAME));
editor.load_history(&history_file_path)?; // We're ok with history load failures. E g this is the case
// for first launch when history file doesnt exist yet
let _ = editor.load_history(&history_file_path);
Ok(Console { Ok(Console {
editor, editor,
...@@ -112,6 +114,11 @@ impl Console { ...@@ -112,6 +114,11 @@ impl Console {
}) })
} }
fn update_history(&mut self, line: &str) -> Result<()> {
self.editor.add_history_entry(line)?;
Ok(self.editor.save_history(&self.history_file_path)?)
}
/// Reads from stdin. Takes into account treating special symbols. /// Reads from stdin. Takes into account treating special symbols.
pub fn read(&mut self) -> Result<Option<String>> { pub fn read(&mut self) -> Result<Option<String>> {
loop { loop {
...@@ -123,8 +130,9 @@ impl Console { ...@@ -123,8 +130,9 @@ impl Console {
ControlFlow::Break(line) => line, ControlFlow::Break(line) => line,
}; };
self.editor.add_history_entry(line.as_str())?; if let Err(e) = self.update_history(&line) {
self.editor.save_history(&self.history_file_path)?; println!("{}: {}", self.history_file_path.display(), e);
}
return Ok(Some(line)); return Ok(Some(line));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment