cleanup some unwrap()
This commit is contained in:
parent
4b650fd82f
commit
f77acc1afd
3 changed files with 31 additions and 10 deletions
|
|
@ -6,7 +6,7 @@ use std::{
|
||||||
|
|
||||||
use console::style;
|
use console::style;
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
use log::debug;
|
use log::{debug, warn};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
cachefile::CacheFile,
|
cachefile::CacheFile,
|
||||||
|
|
@ -89,7 +89,7 @@ impl AppState {
|
||||||
),
|
),
|
||||||
style("/").magenta(),
|
style("/").magenta(),
|
||||||
))
|
))
|
||||||
.unwrap(), // safe as long as the style template is valid
|
.expect("style template is not valid"),
|
||||||
)
|
)
|
||||||
.with_position(uploading.get_offset())
|
.with_position(uploading.get_offset())
|
||||||
.with_message(uploading.get_name().to_owned());
|
.with_message(uploading.get_name().to_owned());
|
||||||
|
|
@ -99,8 +99,9 @@ impl AppState {
|
||||||
}
|
}
|
||||||
drop(slot);
|
drop(slot);
|
||||||
|
|
||||||
// unwrap is safe: We just made sure it's `Some`.
|
Ref::map(self.current_bar.borrow(), |opt| {
|
||||||
Ref::map(self.current_bar.borrow(), |opt| opt.as_ref().unwrap())
|
opt.as_ref().expect("somehow the slot holds None")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finish_bar(&self) {
|
fn finish_bar(&self) {
|
||||||
|
|
@ -113,7 +114,9 @@ impl AppState {
|
||||||
|
|
||||||
pub fn upload_chunk(&mut self) -> sharry::Result<Option<()>> {
|
pub fn upload_chunk(&mut self) -> sharry::Result<Option<()>> {
|
||||||
let Some(mut uploading) = self.inner.pop_file(&self.http) else {
|
let Some(mut uploading) = self.inner.pop_file(&self.http) else {
|
||||||
self.inner.share_notify(&self.http).unwrap(); // HACK unwrap
|
self.inner
|
||||||
|
.share_notify(&self.http)
|
||||||
|
.unwrap_or_else(|e| warn!("Failed to notify the share: {e}"));
|
||||||
|
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ impl CacheFile {
|
||||||
let endpoint = self
|
let endpoint = self
|
||||||
.uri
|
.uri
|
||||||
.endpoint(format!("alias/upload/{}/files/tus", self.share_id));
|
.endpoint(format!("alias/upload/{}/files/tus", self.share_id));
|
||||||
Some(state.start_upload(http, &endpoint, &self.alias_id).unwrap()) // HACK unwrap
|
Some(state.start_upload(http, &endpoint, &self.alias_id).unwrap()) // HACK unwrap, somehow retry
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
||||||
26
src/main.rs
26
src/main.rs
|
|
@ -89,7 +89,13 @@ fn main() {
|
||||||
|
|
||||||
match AppState::from_args(&args) {
|
match AppState::from_args(&args) {
|
||||||
Ok(state) => {
|
Ok(state) => {
|
||||||
state.save().unwrap(); // HACK unwrap
|
state.save().unwrap_or_else(|e| {
|
||||||
|
eprintln!(
|
||||||
|
"{} Failed to save {} state: {e}",
|
||||||
|
style("Warning:").red().bold(),
|
||||||
|
style("ShrUpl").yellow().bold(),
|
||||||
|
)
|
||||||
|
});
|
||||||
state
|
state
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
@ -109,16 +115,28 @@ fn main() {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match state.upload_chunk() {
|
match state.upload_chunk() {
|
||||||
Err(e) => error!("error: {e:?}"),
|
Err(e) => error!("error: {e:?}"), // HACK handle errors better
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
info!("all uploads done");
|
info!("all uploads done");
|
||||||
state.clear().unwrap(); // HACK unwrap
|
state.clear().unwrap_or_else(|e| {
|
||||||
|
eprintln!(
|
||||||
|
"{} Failed to remove {} state: {e}",
|
||||||
|
style("Warning:").red().bold(),
|
||||||
|
style("ShrUpl").yellow().bold(),
|
||||||
|
)
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
state.save().unwrap(); // HACK unwrap
|
state.save().unwrap_or_else(|e| {
|
||||||
|
eprintln!(
|
||||||
|
"{} Failed to save {} state: {e}",
|
||||||
|
style("Warning:").red().bold(),
|
||||||
|
style("ShrUpl").yellow().bold(),
|
||||||
|
)
|
||||||
|
});
|
||||||
check_ctrlc();
|
check_ctrlc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue