about summary refs log tree commit diff
path: root/src/actions/update.rs
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2021-09-21 01:04:49 +0200
committerMel <einebeere@gmail.com>2021-09-21 01:05:03 +0200
commit9e019b462ff05315641c95442faf7f8fc80f76b1 (patch)
tree5813c85887544d865542fb122882a1fb9d2be718 /src/actions/update.rs
parentc25d22681f9bc6ddba512895182af0ce0252731b (diff)
downloadka-9e019b462ff05315641c95442faf7f8fc80f76b1.tar.zst
ka-9e019b462ff05315641c95442faf7f8fc80f76b1.zip
Slightly more consistent error handling
Diffstat (limited to 'src/actions/update.rs')
-rw-r--r--src/actions/update.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/actions/update.rs b/src/actions/update.rs
index a2bc08d..a7d1aad 100644
--- a/src/actions/update.rs
+++ b/src/actions/update.rs
@@ -1,4 +1,6 @@
-use std::io::{self, Read};
+use std::io::Read;
+
+use anyhow::{Context, Result};
 
 use crate::{
     files::{Locations, RepositoryPaths},
@@ -8,12 +10,12 @@ use crate::{
 
 use super::ActionOptions;
 
-pub fn update(command_options: ActionOptions) -> io::Result<()> {
+pub fn update(command_options: ActionOptions) -> Result<()> {
     let locations = Locations::from(&command_options);
 
     let entries = locations
         .get_repository_paths()
-        .expect("Could not traverse files.");
+        .context("Could not traverse files.")?;
 
     for element in entries {
         update_file(element, &locations)?;
@@ -22,11 +24,11 @@ pub fn update(command_options: ActionOptions) -> io::Result<()> {
     Ok(())
 }
 
-fn update_file(paths: RepositoryPaths, locations: &Locations) -> io::Result<()> {
+fn update_file(paths: RepositoryPaths, locations: &Locations) -> Result<()> {
     let new_state = match paths {
         RepositoryPaths::Deleted(deleted) => {
             let mut history_file = deleted.load_history_file()?;
-            let file_history = FileHistory::from_file(&mut history_file).unwrap();
+            let file_history = FileHistory::from_file(&mut history_file)?;
             if !file_history.file_is_deleted() {
                 let mut new_history = file_history;
                 new_history.add_change(FileChange::Deleted);
@@ -55,7 +57,7 @@ fn update_file(paths: RepositoryPaths, locations: &Locations) -> io::Result<()>
             let mut history_file = tracked.load_history_file()?;
             let mut tracked_file = tracked.load_tracked_file()?;
 
-            let file_history = FileHistory::from_file(&mut history_file).unwrap();
+            let file_history = FileHistory::from_file(&mut history_file)?;
 
             let mut new_content = String::new();
             tracked_file.read_to_string(&mut new_content)?;