remove unwrap in s3 io

This commit is contained in:
Qingping Hou 2021-03-07 13:29:24 -08:00 committed by QP Hou
parent f33d496c76
commit 27772bcf4d
2 changed files with 7 additions and 6 deletions

View File

@ -64,6 +64,10 @@ impl ColumnQError {
pub fn json_parse(e: serde_json::Error) -> Self {
Self::LoadJson(format!("Failed to parse JSON data: {}", e))
}
pub fn s3_obj_missing_key() -> Self {
Self::S3Store("Missing key in S3 object list item".to_string())
}
}
impl From<URIReferenceError> for ColumnQError {

View File

@ -71,7 +71,7 @@ fn list_objects<'a>(
futures::stream::unfold(init_state, |mut state| async move {
match state.obj_iter.next() {
Some(obj) => Some((Ok(obj.key.unwrap()), state)),
Some(obj) => Some((obj.key.ok_or_else(ColumnQError::s3_obj_missing_key), state)),
None => match &state.continuation_token {
ContinuationToken::End => None, // terminate stream
ContinuationToken::Value(v) => {
@ -99,15 +99,12 @@ fn list_objects<'a>(
.next_continuation_token
.map(|t| ContinuationToken::Value(Some(t)))
.unwrap_or(ContinuationToken::End);
state.obj_iter = match list_resp.contents {
Some(objs) => objs.into_iter(),
None => Vec::new().into_iter(),
};
state.obj_iter = list_resp.contents.unwrap_or_else(Vec::new).into_iter();
state
.obj_iter
.next()
.map(|obj| (Ok(obj.key.unwrap()), state))
.map(|obj| (obj.key.ok_or_else(ColumnQError::s3_obj_missing_key), state))
}
},
}