errors
This commit is contained in:
@@ -7,6 +7,14 @@ cfg_if! {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(ThisError, Debug, Clone, PartialEq, Eq)]
|
||||
pub enum BumpPortError {
|
||||
#[error("Unsupported architecture")]
|
||||
Unsupported,
|
||||
#[error("Failure: {0}")]
|
||||
Failed(String),
|
||||
}
|
||||
|
||||
pub enum BumpPortType {
|
||||
UDP,
|
||||
TCP,
|
||||
@@ -38,10 +46,10 @@ pub fn udp_port_available(addr: &SocketAddr) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bump_port(addr: &mut SocketAddr, bpt: BumpPortType) -> Result<bool, String> {
|
||||
pub fn bump_port(addr: &mut SocketAddr, bpt: BumpPortType) -> Result<bool, BumpPortError> {
|
||||
cfg_if! {
|
||||
if #[cfg(target_arch = "wasm32")] {
|
||||
Err("unsupported architecture".to_owned())
|
||||
Err(BumpPortError::Unsupported)
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -65,25 +73,25 @@ pub fn bump_port(addr: &mut SocketAddr, bpt: BumpPortType) -> Result<bool, Strin
|
||||
bumped = true;
|
||||
}
|
||||
|
||||
Err("no ports remaining".to_owned())
|
||||
Err(BumpPortError::Failure("no ports remaining".to_owned()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bump_port_string(addr: &mut String, bpt: BumpPortType) -> Result<bool, String> {
|
||||
pub fn bump_port_string(addr: &mut String, bpt: BumpPortType) -> Result<bool, BumpPortError> {
|
||||
cfg_if! {
|
||||
if #[cfg(target_arch = "wasm32")] {
|
||||
return Err("unsupported architecture".to_owned());
|
||||
return Err(BumpPortError::Unsupported);
|
||||
}
|
||||
else
|
||||
{
|
||||
let savec: Vec<SocketAddr> = addr
|
||||
.to_socket_addrs()
|
||||
.map_err(|x| format!("failed to resolve socket address: {}", x))?
|
||||
.map_err(|x| BumpPortError::Failure(format!("failed to resolve socket address: {}", x)))?
|
||||
.collect();
|
||||
|
||||
if savec.len() == 0 {
|
||||
return Err("No socket addresses resolved".to_owned());
|
||||
return Err(BumpPortError::Failure("No socket addresses resolved".to_owned()));
|
||||
}
|
||||
let mut sa = savec.first().unwrap().clone();
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
use super::*;
|
||||
|
||||
#[derive(ThisError, Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EventualError {
|
||||
#[error("Try failed: {0}")]
|
||||
TryFailed(String),
|
||||
}
|
||||
|
||||
pub struct EventualBaseInner<T> {
|
||||
resolved: Option<T>,
|
||||
wakers: BTreeMap<usize, task::Waker>,
|
||||
@@ -92,12 +98,16 @@ impl<T> EventualBaseInner<T> {
|
||||
self.resolved_freelist.clear();
|
||||
}
|
||||
|
||||
pub(super) fn try_reset(&mut self) -> Result<(), String> {
|
||||
pub(super) fn try_reset(&mut self) -> Result<(), EventualError> {
|
||||
if !self.wakers.is_empty() {
|
||||
return Err("Wakers not empty during reset".to_owned());
|
||||
return Err(EventualError::TryFailed(
|
||||
"wakers not empty during reset".to_owned(),
|
||||
));
|
||||
}
|
||||
if !self.resolved_wakers.is_empty() {
|
||||
return Err("Resolved wakers not empty during reset".to_owned());
|
||||
return Err(EventualError::TryFailed(
|
||||
"Resolved wakers not empty during reset".to_owned(),
|
||||
));
|
||||
}
|
||||
self.reset();
|
||||
Ok(())
|
||||
@@ -199,7 +209,7 @@ pub trait EventualCommon: EventualBase {
|
||||
self.base_inner().reset()
|
||||
}
|
||||
|
||||
fn try_reset(&self) -> Result<(), String> {
|
||||
fn try_reset(&self) -> Result<(), EventualError> {
|
||||
self.base_inner().try_reset()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,13 +30,11 @@ macro_rules! bail_io_error_other {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn split_port(name: &str) -> Result<(String, Option<u16>), String> {
|
||||
pub fn split_port(name: &str) -> EyreResult<(String, Option<u16>)> {
|
||||
if let Some(split) = name.rfind(':') {
|
||||
let hoststr = &name[0..split];
|
||||
let portstr = &name[split + 1..];
|
||||
let port: u16 = portstr
|
||||
.parse::<u16>()
|
||||
.map_err(|e| format!("Invalid port: {}", e))?;
|
||||
let port: u16 = portstr.parse::<u16>().wrap_err("invalid port")?;
|
||||
|
||||
Ok((hoststr.to_string(), Some(port)))
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user