Don't panic on open
This commit is contained in:
+4
-2
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user