Skip to content

Commit

Permalink
Handle error when opening file
Browse files Browse the repository at this point in the history
  • Loading branch information
idursun committed Oct 4, 2022
1 parent e8d9442 commit f68eed6
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1622,15 +1622,21 @@ fn read_file_info_buffer(
let filename = args.get(0).unwrap();
let path = PathBuf::from(filename.to_string());
if path.exists() {
let file = std::fs::File::open(path)?;
let mut reader = BufReader::new(file);

match from_reader(&mut reader, doc.encoding()) {
Ok(contents) => {
let contents = Tendril::from(contents);
let selection = doc.selection(view.id);
let transaction = Transaction::insert(doc.text(), selection, contents);
doc.apply(&transaction, view.id);
match std::fs::File::open(path) {
Ok(file) => {
let mut reader = BufReader::new(file);

match from_reader(&mut reader, doc.encoding()) {
Ok(contents) => {
let contents = Tendril::from(contents);
let selection = doc.selection(view.id);
let transaction = Transaction::insert(doc.text(), selection, contents);
doc.apply(&transaction, view.id);
}
Err(error) => cx
.editor
.set_error(format!("error reading file: {}", error)),
}
}
Err(error) => cx
.editor
Expand Down

0 comments on commit f68eed6

Please sign in to comment.