Don't panic on open

This commit is contained in:
Greg Shuflin
2024-03-01 09:56:14 -08:00
parent c2d3d388ae
commit 904a0cbc53
2 changed files with 15 additions and 2 deletions
+4 -2
View File
@@ -91,7 +91,7 @@ impl EditorCore {
fn load_file(&mut self, file: &Path) -> Result<(), BasicError> {
info!(file=%file.display(), "Opening file");
//TODO needs to be an async operation
let s = std::fs::read_to_string(file).unwrap();
let s = std::fs::read_to_string(file)?;
let new_buffer = TextBuffer::new_with_text(self.active_buffer, s);
self.buffers.insert(self.active_buffer, new_buffer);
Ok(())
@@ -108,7 +108,9 @@ impl EditorCore {
CommandOutput::Error(err) => {
error!(err, "Command Output Error");
}
}
};
self.handle_action(EditorAction::TransitionToMode(Mode::Normal));
}
}
+11
View File
@@ -5,6 +5,7 @@ use tracing::error;
#[derive(Debug)]
pub(crate) struct BasicError {
kind: BasicErrorKind,
//tag: Vec<(String, String)>,
}
impl Display for BasicError {
@@ -13,15 +14,25 @@ impl Display for BasicError {
}
}
impl From<std::io::Error> for BasicError {
fn from(value: std::io::Error) -> Self {
Self {
kind: BasicErrorKind::IOError,
}
}
}
#[derive(Debug)]
pub(crate) enum BasicErrorKind {
FileOpen,
IOError,
}
impl Display for BasicErrorKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
BasicErrorKind::FileOpen => write!(f, "File opening error"),
BasicErrorKind::IOError => write!(f, "IO error"),
}
}
}