diff options
| author | Mel <einebeere@gmail.com> | 2021-09-21 01:04:49 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2021-09-21 01:05:03 +0200 |
| commit | 9e019b462ff05315641c95442faf7f8fc80f76b1 (patch) | |
| tree | 5813c85887544d865542fb122882a1fb9d2be718 /src/actions/shift.rs | |
| parent | c25d22681f9bc6ddba512895182af0ce0252731b (diff) | |
| download | ka-9e019b462ff05315641c95442faf7f8fc80f76b1.tar.zst ka-9e019b462ff05315641c95442faf7f8fc80f76b1.zip | |
Slightly more consistent error handling
Diffstat (limited to 'src/actions/shift.rs')
| -rw-r--r-- | src/actions/shift.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/actions/shift.rs b/src/actions/shift.rs index c02f0ed..1bd8864 100644 --- a/src/actions/shift.rs +++ b/src/actions/shift.rs @@ -1,9 +1,11 @@ use std::{ fs, - io::{self, Seek, Write}, + io::{Seek, Write}, path::Path, }; +use anyhow::Result; + use crate::{ files::{Locations, RepositoryPaths}, history::FileHistory, @@ -11,14 +13,14 @@ use crate::{ use super::ActionOptions; -pub fn shift(command_options: ActionOptions, path: &str, new_cursor: usize) -> io::Result<()> { +pub fn shift(command_options: ActionOptions, path: &str, new_cursor: usize) -> Result<()> { let locations = Locations::from(&command_options); - match RepositoryPaths::from_tracked(&locations, Path::new(path)) { + match RepositoryPaths::from_tracked(&locations, Path::new(path))? { RepositoryPaths::Tracked(tracked) => { let mut history_file = tracked.load_history_file()?; - let mut file_history = FileHistory::from_file(&mut history_file).unwrap(); + let mut file_history = FileHistory::from_file(&mut history_file)?; file_history.set_cursor(new_cursor); if file_history.file_is_deleted() { @@ -38,7 +40,7 @@ pub fn shift(command_options: ActionOptions, path: &str, new_cursor: usize) -> i RepositoryPaths::Deleted(deleted) => { let mut history_file = deleted.load_history_file()?; - let mut file_history = FileHistory::from_file(&mut history_file).unwrap(); + let mut file_history = FileHistory::from_file(&mut history_file)?; file_history.set_cursor(new_cursor); if !file_history.file_is_deleted() { |
