mirror of
https://github.com/bytedance/g3.git
synced 2026-05-13 07:01:48 +00:00
use less String in error types
This commit is contained in:
parent
fa2800749b
commit
cc584f07e0
10 changed files with 30 additions and 44 deletions
|
|
@ -191,9 +191,9 @@ impl DirectFixedEscaper {
|
|||
let ips = resolver_job
|
||||
.get_r1_or_first(self.config.happy_eyeballs.resolution_delay(), usize::MAX)
|
||||
.await?;
|
||||
strategy.pick_best(ips).ok_or_else(|| {
|
||||
ResolveError::UnexpectedError("no upstream ip can be selected".to_string())
|
||||
})
|
||||
strategy
|
||||
.pick_best(ips)
|
||||
.ok_or_else(|| ResolveError::UnexpectedError("no upstream ip can be selected"))
|
||||
}
|
||||
|
||||
async fn redirect_get_best(
|
||||
|
|
|
|||
|
|
@ -359,9 +359,9 @@ impl DirectFloatEscaper {
|
|||
let ips = resolver_job
|
||||
.get_r1_or_first(self.config.happy_eyeballs.resolution_delay(), usize::MAX)
|
||||
.await?;
|
||||
strategy.pick_best(ips).ok_or_else(|| {
|
||||
ResolveError::UnexpectedError("no upstream ip can be selected".to_string())
|
||||
})
|
||||
strategy
|
||||
.pick_best(ips)
|
||||
.ok_or_else(|| ResolveError::UnexpectedError("no upstream ip can be selected"))
|
||||
}
|
||||
|
||||
async fn redirect_get_best(
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ impl RouteGeoIpEscaper {
|
|||
.await?;
|
||||
self.config.resolve_strategy.pick_best(v).ok_or_else(|| {
|
||||
ResolveError::UnexpectedError(
|
||||
"resolver job return ok but with no ip can be selected".to_string(),
|
||||
"resolver job return ok but with no ip can be selected",
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ impl RouteResolvedEscaper {
|
|||
.await?;
|
||||
self.config.resolve_strategy.pick_best(v).ok_or_else(|| {
|
||||
ResolveError::UnexpectedError(
|
||||
"resolver job return ok but with no ip can be selected".to_string(),
|
||||
"resolver job return ok but with no ip can be selected",
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -446,9 +446,7 @@ impl ArriveFirstResolveJob {
|
|||
) -> Poll<Result<IpAddr, ResolveError>> {
|
||||
let ips = ready!(self.poll_all_addrs(cx))?;
|
||||
let ip = self.strategy.pick_best(ips).ok_or_else(|| {
|
||||
ResolveError::UnexpectedError(
|
||||
"resolver job return ok but with no ip can be selected".to_string(),
|
||||
)
|
||||
ResolveError::UnexpectedError("resolver job return ok but with no ip can be selected")
|
||||
})?;
|
||||
Poll::Ready(Ok(ip))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ pub enum IcapReqmodParseError {
|
|||
InvalidHeaderLine(IcapLineParseError),
|
||||
#[error("no ISTag set")]
|
||||
NoServiceTagSet,
|
||||
#[error("unsupported body")]
|
||||
UnsupportedBody(String),
|
||||
#[error("unsupported body: {0}")]
|
||||
UnsupportedBody(&'static str),
|
||||
#[error("invalid value for header {0}")]
|
||||
InvalidHeaderValue(&'static str),
|
||||
#[error("io failed: {0:?}")]
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ impl IcapReqmodResponsePayload {
|
|||
.ok_or(IcapReqmodParseError::InvalidHeaderValue("Encapsulated"))?;
|
||||
if value.ne("0") {
|
||||
return Err(IcapReqmodParseError::UnsupportedBody(
|
||||
"invalid hdr byte-offsets value".to_string(),
|
||||
"invalid hdr byte-offsets value",
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -49,27 +49,23 @@ impl IcapReqmodResponsePayload {
|
|||
let body_part = parts
|
||||
.next()
|
||||
.ok_or_else(|| {
|
||||
IcapReqmodParseError::UnsupportedBody(
|
||||
"no body byte-offsets pair found".to_string(),
|
||||
)
|
||||
IcapReqmodParseError::UnsupportedBody("no body byte-offsets pair found")
|
||||
})?
|
||||
.trim();
|
||||
let (name, value) = body_part.split_once('=').ok_or_else(|| {
|
||||
IcapReqmodParseError::UnsupportedBody(
|
||||
"invalid body byte-offsets pair".to_string(),
|
||||
)
|
||||
IcapReqmodParseError::UnsupportedBody("invalid body byte-offsets pair")
|
||||
})?;
|
||||
let (hdr_len, offset) = usize::from_radix_10(value.as_bytes());
|
||||
if offset != value.len() {
|
||||
return Err(IcapReqmodParseError::UnsupportedBody(
|
||||
"invalid body byte-offsets value".to_string(),
|
||||
"invalid body byte-offsets value",
|
||||
));
|
||||
}
|
||||
match name.to_lowercase().as_str() {
|
||||
"req-body" => Ok(IcapReqmodResponsePayload::HttpRequestWithBody(hdr_len)),
|
||||
"null-body" => Ok(IcapReqmodResponsePayload::HttpRequestWithoutBody(hdr_len)),
|
||||
_ => Err(IcapReqmodParseError::UnsupportedBody(
|
||||
"invalid body byte-offsets name".to_string(),
|
||||
"invalid body byte-offsets name",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
|
@ -77,33 +73,29 @@ impl IcapReqmodResponsePayload {
|
|||
let body_part = parts
|
||||
.next()
|
||||
.ok_or_else(|| {
|
||||
IcapReqmodParseError::UnsupportedBody(
|
||||
"no body byte-offsets pair found".to_string(),
|
||||
)
|
||||
IcapReqmodParseError::UnsupportedBody("no body byte-offsets pair found")
|
||||
})?
|
||||
.trim();
|
||||
let (name, value) = body_part.split_once('=').ok_or_else(|| {
|
||||
IcapReqmodParseError::UnsupportedBody(
|
||||
"invalid body byte-offsets pair".to_string(),
|
||||
)
|
||||
IcapReqmodParseError::UnsupportedBody("invalid body byte-offsets pair")
|
||||
})?;
|
||||
let (hdr_len, offset) = usize::from_radix_10(value.as_bytes());
|
||||
if offset != value.len() {
|
||||
return Err(IcapReqmodParseError::UnsupportedBody(
|
||||
"invalid body byte-offsets value".to_string(),
|
||||
"invalid body byte-offsets value",
|
||||
));
|
||||
}
|
||||
match name.to_lowercase().as_str() {
|
||||
"res-body" => Ok(IcapReqmodResponsePayload::HttpResponseWithBody(hdr_len)),
|
||||
"null-body" => Ok(IcapReqmodResponsePayload::HttpResponseWithoutBody(hdr_len)),
|
||||
_ => Err(IcapReqmodParseError::UnsupportedBody(
|
||||
"invalid body byte-offsets name".to_string(),
|
||||
"invalid body byte-offsets name",
|
||||
)),
|
||||
}
|
||||
}
|
||||
"null-body" => Ok(IcapReqmodResponsePayload::NoPayload),
|
||||
_ => Err(IcapReqmodParseError::UnsupportedBody(
|
||||
"invalid hdr byte-offsets value".to_string(),
|
||||
"invalid hdr byte-offsets value",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ pub enum IcapRespmodParseError {
|
|||
InvalidHeaderLine(IcapLineParseError),
|
||||
#[error("no ISTag set")]
|
||||
NoServiceTagSet,
|
||||
#[error("unsupported body")]
|
||||
UnsupportedBody(String),
|
||||
#[error("unsupported body: {0}")]
|
||||
UnsupportedBody(&'static str),
|
||||
#[error("invalid value for header {0}")]
|
||||
InvalidHeaderValue(&'static str),
|
||||
#[error("io failed: {0:?}")]
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ impl IcapRespmodResponsePayload {
|
|||
.ok_or(IcapRespmodParseError::InvalidHeaderValue("Encapsulated"))?;
|
||||
if value.ne("0") {
|
||||
return Err(IcapRespmodParseError::UnsupportedBody(
|
||||
"invalid hdr byte-offsets value".to_string(),
|
||||
"invalid hdr byte-offsets value",
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -47,33 +47,29 @@ impl IcapRespmodResponsePayload {
|
|||
let body_part = parts
|
||||
.next()
|
||||
.ok_or_else(|| {
|
||||
IcapRespmodParseError::UnsupportedBody(
|
||||
"no body byte-offsets pair found".to_string(),
|
||||
)
|
||||
IcapRespmodParseError::UnsupportedBody("no body byte-offsets pair found")
|
||||
})?
|
||||
.trim();
|
||||
let (name, value) = body_part.split_once('=').ok_or_else(|| {
|
||||
IcapRespmodParseError::UnsupportedBody(
|
||||
"invalid body byte-offsets pair".to_string(),
|
||||
)
|
||||
IcapRespmodParseError::UnsupportedBody("invalid body byte-offsets pair")
|
||||
})?;
|
||||
let (hdr_len, offset) = usize::from_radix_10(value.as_bytes());
|
||||
if offset != value.len() {
|
||||
return Err(IcapRespmodParseError::UnsupportedBody(
|
||||
"invalid body byte-offsets value".to_string(),
|
||||
"invalid body byte-offsets value",
|
||||
));
|
||||
}
|
||||
match name.to_lowercase().as_str() {
|
||||
"res-body" => Ok(IcapRespmodResponsePayload::HttpResponseWithBody(hdr_len)),
|
||||
"null-body" => Ok(IcapRespmodResponsePayload::HttpResponseWithoutBody(hdr_len)),
|
||||
_ => Err(IcapRespmodParseError::UnsupportedBody(
|
||||
"invalid body byte-offsets name".to_string(),
|
||||
"invalid body byte-offsets name",
|
||||
)),
|
||||
}
|
||||
}
|
||||
"null-body" => Ok(IcapRespmodResponsePayload::NoPayload),
|
||||
_ => Err(IcapRespmodParseError::UnsupportedBody(
|
||||
"invalid hdr byte-offsets value".to_string(),
|
||||
"invalid hdr byte-offsets value",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ pub enum ResolveError {
|
|||
#[error("local error: {0}")]
|
||||
FromLocal(#[from] ResolveLocalError),
|
||||
#[error("unexpected error: {0}")]
|
||||
UnexpectedError(String),
|
||||
UnexpectedError(&'static str),
|
||||
}
|
||||
|
||||
impl ResolveError {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue