clippy: fix result_unit_err warnings (#31791)

* clippy: fix `result_unit_err` warnings

* feat: fix result warnings in script

* doc: document `generate_key` return type

Co-authored-by: Martin Robinson <mrobinson@igalia.com>

* feat: add back result to RangeRequestBounds::get_final

Co-authored-by: Martin Robinson <mrobinson@igalia.com>

---------

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
eri 2024-03-21 13:51:45 +01:00 committed by GitHub
parent ea62a5e24f
commit da696b7e57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 175 additions and 191 deletions

View file

@ -25,6 +25,12 @@ pub struct CookieStorage {
max_per_host: usize,
}
#[derive(Debug)]
pub enum RemoveCookieError {
Overlapping,
NonHTTP,
}
impl CookieStorage {
pub fn new(max_cookies: usize) -> CookieStorage {
CookieStorage {
@ -40,7 +46,7 @@ impl CookieStorage {
cookie: &Cookie,
url: &ServoUrl,
source: CookieSource,
) -> Result<Option<Cookie>, ()> {
) -> Result<Option<Cookie>, RemoveCookieError> {
let domain = reg_host(cookie.cookie.domain().as_ref().unwrap_or(&""));
let cookies = self.cookies_map.entry(domain).or_default();
@ -61,7 +67,7 @@ impl CookieStorage {
});
if any_overlapping {
return Err(());
return Err(RemoveCookieError::Overlapping);
}
}
@ -80,7 +86,7 @@ impl CookieStorage {
if c.cookie.http_only().unwrap_or(false) && source == CookieSource::NonHTTP {
// Undo the removal.
cookies.push(c);
Err(())
Err(RemoveCookieError::NonHTTP)
} else {
Ok(Some(c))
}

View file

@ -569,7 +569,7 @@ pub enum RangeRequestBounds {
}
impl RangeRequestBounds {
pub fn get_final(&self, len: Option<u64>) -> Result<RelativePos, ()> {
pub fn get_final(&self, len: Option<u64>) -> Result<RelativePos, &'static str> {
match self {
RangeRequestBounds::Final(pos) => {
if let Some(len) = len {
@ -577,7 +577,7 @@ impl RangeRequestBounds {
return Ok(pos.clone());
}
}
Err(())
Err("Tried to process RangeRequestBounds::Final without len")
},
RangeRequestBounds::Pending(offset) => Ok(RelativePos::from_opts(
if let Some(len) = len {
@ -750,12 +750,10 @@ async fn scheme_fetch(
let range_header = request.headers.typed_get::<Range>();
let is_range_request = range_header.is_some();
let range = match get_range_request_bounds(range_header).get_final(file_size) {
Ok(range) => range,
Err(_) => {
range_not_satisfiable_error(&mut response);
return response;
},
let Ok(range) = get_range_request_bounds(range_header).get_final(file_size)
else {
range_not_satisfiable_error(&mut response);
return response;
};
let mut reader = BufReader::with_capacity(FILE_CHUNK_SIZE, file);
if reader.seek(SeekFrom::Start(range.start as u64)).is_err() {

View file

@ -293,12 +293,9 @@ impl FileManager {
let file_impl = self.store.get_impl(id, file_token, origin_in)?;
match file_impl {
FileImpl::Memory(buf) => {
let range = match range.get_final(Some(buf.size)) {
Ok(range) => range,
Err(_) => {
return Err(BlobURLStoreError::InvalidRange);
},
};
let range = range
.get_final(Some(buf.size))
.map_err(|_| BlobURLStoreError::InvalidRange)?;
let range = range.to_abs_range(buf.size as usize);
let len = range.len() as u64;
@ -328,12 +325,9 @@ impl FileManager {
let file = File::open(&metadata.path)
.map_err(|e| BlobURLStoreError::External(e.to_string()))?;
let range = match range.get_final(Some(metadata.size)) {
Ok(range) => range,
Err(_) => {
return Err(BlobURLStoreError::InvalidRange);
},
};
let range = range
.get_final(Some(metadata.size))
.map_err(|_| BlobURLStoreError::InvalidRange)?;
let mut reader = BufReader::with_capacity(FILE_CHUNK_SIZE, file);
if reader.seek(SeekFrom::Start(range.start as u64)).is_err() {