Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 plugin does not reply with errors when queried key is not found #27

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ impl Storage for S3Storage {

let prefix = self.config.path_prefix.to_owned();
let s3_key = S3Key::from_key_expr(prefix, key.to_owned())?;
let (timestamp, value) = self.get_stored_value(&s3_key.into()).await?;

let stored_data = StoredData { value, timestamp };
Ok(vec![stored_data])
let get_result = self.get_stored_value(&s3_key.into()).await?;
if let Some((timestamp, value)) = get_result {
let stored_data = StoredData { value, timestamp };
Ok(vec![stored_data])
} else {
Ok(vec![])
}
}

/// Function called for each incoming data ([`Sample`]) to be stored in this storage.
Expand Down Expand Up @@ -317,15 +321,24 @@ impl Storage for S3Storage {
}

impl S3Storage {
async fn get_stored_value(&self, key: &String) -> ZResult<(Timestamp, Value)> {
async fn get_stored_value(&self, key: &String) -> ZResult<Option<(Timestamp, Value)>> {
let client2 = self.client.clone();
let key2 = key.to_owned();
let output_result = self

let output_result = match self
.runtime
.spawn(async move { client2.get_object(key2.as_str()).await })
.await
.map_err(|e| zerror!("Get operation failed for key '{key}': {e}"))?
.map_err(|e| zerror!("Get operation failed for key '{key}': {e}"))?;
{
Ok(result) => Ok(result),
Err(e) => {
if e.to_string().contains("NoSuchKey") {
return Ok(None);
}
Err(zerror!("Get operation failed for key '{key}': {e}"))
}
}?;

let metadata = output_result
.metadata
Expand Down Expand Up @@ -354,7 +367,7 @@ impl S3Storage {
),
None => Value::from(Vec::from(bytes)),
};
Ok((timestamp, value))
Ok(Some((timestamp, value)))
}
}

Expand Down
Loading