Ensure we dont crash if there are no files found
This commit is contained in:
parent
fd3d2ec8dc
commit
87d5852986
1 changed files with 14 additions and 10 deletions
|
@ -60,18 +60,22 @@ pub fn remove_command(module: &Module, env: CommandEnv) -> CommandResult {
|
||||||
debug!("Remove by id: {}", id);
|
debug!("Remove by id: {}", id);
|
||||||
|
|
||||||
let parser = Parser::new(JsonHeaderParser::new(None));
|
let parser = Parser::new(JsonHeaderParser::new(None));
|
||||||
let file = env.bk.get_file_by_id(module, &id.into(), &parser).unwrap();
|
env.bk.get_file_by_id(module, &id.into(), &parser).map(|file| {
|
||||||
debug!("Remove file : {:?}", file);
|
debug!("Remove file : {:?}", file);
|
||||||
|
|
||||||
if let Err(e) = env.bk.remove_file(module, file, checked) {
|
if let Err(e) = env.bk.remove_file(module, file, checked) {
|
||||||
debug!("Remove failed");
|
debug!("Remove failed");
|
||||||
let mut err = ModuleError::new("Removing file failed");
|
let mut err = ModuleError::new("Removing file failed");
|
||||||
err.caused_by = Some(Box::new(e));
|
err.caused_by = Some(Box::new(e));
|
||||||
Err(err)
|
Err(err)
|
||||||
} else {
|
} else {
|
||||||
debug!("Remove worked");
|
info!("Remove worked");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}).unwrap_or({
|
||||||
|
info!("No files found");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
})
|
||||||
} else {
|
} else {
|
||||||
debug!("Remove more than one file");
|
debug!("Remove more than one file");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue