Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33317209
D5856.1768831356.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D5856.1768831356.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
Mon, Jan 19, 2:02 PM (20 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5956478
Default Alt Text
D5856.1768831356.diff (1 KB)
Attached To
Mode
D5856: [services][blob] Define database error types
Attached
Detach File
Event Timeline
Log In to Comment