mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-12-22 22:59:27 +00:00
disk: handle some [.unwrap()]s correctly
This commit is contained in:
parent
ddec9fcb6d
commit
3ac0b98802
3 changed files with 43 additions and 11 deletions
38
src/disk.rs
38
src/disk.rs
|
@ -347,10 +347,22 @@ impl Node {
|
|||
let size = nodes.keys().len();
|
||||
let mut vec = Vec::with_capacity(size);
|
||||
for (key, values) in nodes.iter() {
|
||||
let ip = match values.get("ip") {
|
||||
Some(ip) => ip.to_string(),
|
||||
None => { error!("Node | [None] at [ip] parse"); return Err(TomlError::Parse("[None] at [ip] parse")) },
|
||||
};
|
||||
let rpc = match values.get("rpc") {
|
||||
Some(rpc) => rpc.to_string(),
|
||||
None => { error!("Node | [None] at [rpc] parse"); return Err(TomlError::Parse("[None] at [rpc] parse")) },
|
||||
};
|
||||
let zmq = match values.get("zmq") {
|
||||
Some(zmq) => zmq.to_string(),
|
||||
None => { error!("Node | [None] at [zmq] parse"); return Err(TomlError::Parse("[None] at [zmq] parse")) },
|
||||
};
|
||||
let node = Node {
|
||||
ip: values.get("ip").unwrap().as_str().unwrap().to_string(),
|
||||
rpc: values.get("rpc").unwrap().as_str().unwrap().to_string(),
|
||||
zmq: values.get("zmq").unwrap().as_str().unwrap().to_string(),
|
||||
ip,
|
||||
rpc,
|
||||
zmq,
|
||||
};
|
||||
vec.push((key.clone(), node));
|
||||
}
|
||||
|
@ -459,10 +471,22 @@ impl Pool {
|
|||
let size = pools.keys().len();
|
||||
let mut vec = Vec::with_capacity(size);
|
||||
for (key, values) in pools.iter() {
|
||||
let rig = match values.get("rig") {
|
||||
Some(rig) => rig.to_string(),
|
||||
None => { error!("Pool | [None] at [rig] parse"); return Err(TomlError::Parse("[None] at [rig] parse")) },
|
||||
};
|
||||
let ip = match values.get("ip") {
|
||||
Some(ip) => ip.to_string(),
|
||||
None => { error!("Pool | [None] at [ip] parse"); return Err(TomlError::Parse("[None] at [ip] parse")) },
|
||||
};
|
||||
let port = match values.get("port") {
|
||||
Some(port) => port.to_string(),
|
||||
None => { error!("Pool | [None] at [port] parse"); return Err(TomlError::Parse("[None] at [port] parse")) },
|
||||
};
|
||||
let pool = Pool {
|
||||
rig: values.get("rig").unwrap().as_str().unwrap().to_string(),
|
||||
ip: values.get("ip").unwrap().as_str().unwrap().to_string(),
|
||||
port: values.get("port").unwrap().as_str().unwrap().to_string(),
|
||||
rig,
|
||||
ip,
|
||||
port,
|
||||
};
|
||||
vec.push((key.clone(), pool));
|
||||
}
|
||||
|
@ -527,6 +551,7 @@ pub enum TomlError {
|
|||
Deserialize(toml::de::Error),
|
||||
Merge(figment::Error),
|
||||
Format(std::fmt::Error),
|
||||
Parse(&'static str),
|
||||
}
|
||||
|
||||
impl Display for TomlError {
|
||||
|
@ -539,6 +564,7 @@ impl Display for TomlError {
|
|||
Deserialize(err) => write!(f, "{}: Deserialize | {}", ERROR, err),
|
||||
Merge(err) => write!(f, "{}: Merge | {}", ERROR, err),
|
||||
Format(err) => write!(f, "{}: Format | {}", ERROR, err),
|
||||
Parse(err) => write!(f, "{}: Parse | {}", ERROR, err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -175,7 +175,10 @@ impl App {
|
|||
.with_processes(sysinfo::ProcessRefreshKind::new().with_cpu())
|
||||
.with_memory());
|
||||
sysinfo.refresh_all();
|
||||
let pid = sysinfo::get_current_pid().unwrap();
|
||||
let pid = match sysinfo::get_current_pid() {
|
||||
Ok(pid) => pid,
|
||||
Err(e) => { error!("App Init | Failed to get sysinfo PID: {}", e); exit(1) }
|
||||
};
|
||||
let pub_sys = Arc::new(Mutex::new(Sys::new()));
|
||||
|
||||
debug!("App Init | The rest of the [App]...");
|
||||
|
@ -275,6 +278,7 @@ impl App {
|
|||
Deserialize(e) => app.error_state.set(format!("State file: {}", e), ErrorFerris::Panic, ErrorButtons::Quit),
|
||||
Format(e) => app.error_state.set(format!("State file: {}", e), ErrorFerris::Panic, ErrorButtons::Quit),
|
||||
Merge(e) => app.error_state.set(format!("State file: {}", e), ErrorFerris::Error, ErrorButtons::ResetState),
|
||||
_ => (),
|
||||
};
|
||||
State::new()
|
||||
},
|
||||
|
@ -291,8 +295,9 @@ impl App {
|
|||
Path(e) => app.error_state.set(format!("Node list: {}", e), ErrorFerris::Panic, ErrorButtons::Quit),
|
||||
Serialize(e) => app.error_state.set(format!("Node list: {}", e), ErrorFerris::Panic, ErrorButtons::Quit),
|
||||
Deserialize(e) => app.error_state.set(format!("Node list: {}", e), ErrorFerris::Panic, ErrorButtons::Quit),
|
||||
Format(e) => app.error_state.set(format!("Node file: {}", e), ErrorFerris::Panic, ErrorButtons::Quit),
|
||||
Format(e) => app.error_state.set(format!("Node list: {}", e), ErrorFerris::Panic, ErrorButtons::Quit),
|
||||
Merge(e) => app.error_state.set(format!("Node list: {}", e), ErrorFerris::Error, ErrorButtons::ResetState),
|
||||
Parse(e) => app.error_state.set(format!("Node list: {}", e), ErrorFerris::Panic, ErrorButtons::Quit),
|
||||
};
|
||||
Node::new_vec()
|
||||
},
|
||||
|
@ -311,8 +316,9 @@ impl App {
|
|||
Path(e) => app.error_state.set(format!("Pool list: {}", e), ErrorFerris::Panic, ErrorButtons::Quit),
|
||||
Serialize(e) => app.error_state.set(format!("Pool list: {}", e), ErrorFerris::Panic, ErrorButtons::Quit),
|
||||
Deserialize(e) => app.error_state.set(format!("Pool list: {}", e), ErrorFerris::Panic, ErrorButtons::Quit),
|
||||
Format(e) => app.error_state.set(format!("Pool file: {}", e), ErrorFerris::Panic, ErrorButtons::Quit),
|
||||
Format(e) => app.error_state.set(format!("Pool list: {}", e), ErrorFerris::Panic, ErrorButtons::Quit),
|
||||
Merge(e) => app.error_state.set(format!("Pool list: {}", e), ErrorFerris::Error, ErrorButtons::ResetState),
|
||||
Parse(e) => app.error_state.set(format!("Pool list: {}", e), ErrorFerris::Panic, ErrorButtons::Quit),
|
||||
};
|
||||
Pool::new_vec()
|
||||
},
|
||||
|
|
|
@ -284,12 +284,12 @@ impl Ping {
|
|||
.header("User-Agent", rand_user_agent)
|
||||
.body(hyper::Body::from(r#"{"jsonrpc":"2.0","id":"0","method":"get_info"}"#))
|
||||
.unwrap();
|
||||
let handle = tokio::spawn(async move { Self::response(client, request, ip, ping, percent, node_vec).await });
|
||||
let handle = tokio::task::spawn(async move { Self::response(client, request, ip, ping, percent, node_vec).await; });
|
||||
handles.push(handle);
|
||||
}
|
||||
|
||||
for handle in handles {
|
||||
handle.await?;
|
||||
handle.await;
|
||||
}
|
||||
|
||||
let node_vec = std::mem::take(&mut *node_vec.lock().unwrap());
|
||||
|
|
Loading…
Reference in a new issue