improve error handling
This commit is contained in:
		
							parent
							
								
									6389bb988d
								
							
						
					
					
						commit
						d9fe8b8160
					
				@ -81,10 +81,14 @@ impl LockedFileGuard {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn replace_contents(&mut self, new_content: String) -> Result<(), crate::UserLibError> {
 | 
					    pub fn replace_contents(&mut self, new_content: String) -> Result<(), crate::UserLibError> {
 | 
				
			||||||
        self.file = File::create(&self.path).expect("Failed to truncate file.");
 | 
					        self.file = match File::create(&self.path) {
 | 
				
			||||||
        self.file
 | 
					            Ok(file) => file,
 | 
				
			||||||
            .write_all(&new_content.into_bytes())
 | 
					            Err(e) => return Err(("Failed to truncate file.".to_owned(), e).into()),
 | 
				
			||||||
            .expect("Failed to write all users.");
 | 
					        };
 | 
				
			||||||
 | 
					        match self.file.write_all(&new_content.into_bytes()) {
 | 
				
			||||||
 | 
					            Ok(_) => (),
 | 
				
			||||||
 | 
					            Err(e) => return Err(("Could not write (all) users. ".to_owned(), e).into()),
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
        let _ = self.file.write("\n".as_bytes());
 | 
					        let _ = self.file.write("\n".as_bytes());
 | 
				
			||||||
        Ok(())
 | 
					        Ok(())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user