Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3717869
D5856.id19303.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D5856.id19303.diff
View Options
diff --git a/services/blob/src/database.rs b/services/blob/src/database.rs
--- a/services/blob/src/database.rs
+++ b/services/blob/src/database.rs
@@ -1,7 +1,13 @@
use anyhow::{anyhow, Context, Result};
-use aws_sdk_dynamodb::{model::AttributeValue, output::GetItemOutput};
+use aws_sdk_dynamodb::{
+ model::AttributeValue, output::GetItemOutput, Error as DynamoDBError,
+};
use chrono::{DateTime, Utc};
-use std::{collections::HashMap, sync::Arc};
+use std::{
+ collections::HashMap,
+ fmt::{Display, Formatter},
+ sync::Arc,
+};
use crate::{
constants::{
@@ -263,6 +269,53 @@
}
}
+#[derive(
+ Debug, derive_more::Display, derive_more::From, derive_more::Error,
+)]
+pub enum Error {
+ #[display(...)]
+ AwsSdk(DynamoDBError),
+ #[display(...)]
+ Attribute(DBItemError),
+}
+
+#[derive(Debug, derive_more::Error, derive_more::Constructor)]
+pub struct DBItemError {
+ attribute_name: &'static str,
+ attribute_value: Option<AttributeValue>,
+ attribute_error: DBItemAttributeError,
+}
+
+impl Display for DBItemError {
+ fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
+ match &self.attribute_error {
+ DBItemAttributeError::Missing => {
+ write!(f, "Attribute {} is missing", self.attribute_name)
+ }
+ DBItemAttributeError::IncorrectType => write!(
+ f,
+ "Value for attribute {} has incorrect type: {:?}",
+ self.attribute_name, self.attribute_value
+ ),
+ error => write!(
+ f,
+ "Error regarding attribute {} with value {:?}: {}",
+ self.attribute_name, self.attribute_value, error
+ ),
+ }
+ }
+}
+
+#[derive(Debug, derive_more::Display, derive_more::Error)]
+pub enum DBItemAttributeError {
+ #[display(...)]
+ Missing,
+ #[display(...)]
+ IncorrectType,
+ #[display(...)]
+ InvalidTimestamp(chrono::ParseError),
+}
+
fn parse_string_attribute(attribute: Option<AttributeValue>) -> Result<String> {
match attribute {
Some(AttributeValue::S(str_value)) => Ok(str_value),
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 9, 10:21 AM (5 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2832999
Default Alt Text
D5856.id19303.diff (1 KB)
Attached To
Mode
D5856: [services][blob] Define database error types
Attached
Detach File
Event Timeline
Log In to Comment