JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Remove unwrap statements and return OperationError's

erremilia - ⁨2⁩ years ago

parent: tbd commit: ⁨cf491a4

Showing ⁨⁨4⁩ changed files⁩ with ⁨⁨10⁩ insertions⁩ and ⁨⁨6⁩ deletions⁩

giterated-models/src/object.rs

View file
@@ -80,8 +80,7 @@ impl<
80 80 },
81 81 operation_state,
82 82 )
83 .await
84 .unwrap();
83 .await?;
85 84
86 85 Ok(serde_json::from_slice(&result).unwrap())
87 86 }

giterated-models/src/settings/operations.rs

View file
@@ -40,4 +40,7 @@ impl<O: GiteratedObject> GiteratedOperation<O> for SetSetting {
40 40 }
41 41
42 42 #[derive(Error, Debug, Serialize, Deserialize, Clone)]
43 pub enum SetSettingError {}
43 pub enum SetSettingError {
44 #[error("Invalid setting `{0}` on object `{0}`")]
45 InvalidSetting(String, String)
46 }

giterated-stack/src/handler/mod.rs

View file
@@ -123,6 +123,7 @@ impl<P, O, E> HandlerWrapper<P, O, E> {
123 123 F: Fn(&N, &StackOperationState) -> Result<P, OperationError<R>> + Clone + Send + Sync,
124 124 R: std::fmt::Debug + 'static,
125 125 E: Into<OperationError<R>> + 'static,
126 OperationError<R>: From<OperationError<E>> + 'static,
126 127 F: 'static,
127 128 N: 'static,
128 129 P: 'static,
@@ -143,7 +144,7 @@ impl<P, O, E> HandlerWrapper<P, O, E> {
143 144 let operation_state = operation_state;
144 145 match (func)(predicate_output, state, operation_state).await {
145 146 Ok(success) => Ok(success),
146 Err(_) => todo!(),
147 Err(err) => Err(err.into()),
147 148 }
148 149 }
149 150 .boxed_local()

giterated-stack/src/stack.rs

View file
@@ -8,7 +8,7 @@ use giterated_models::error::{GetValueError, IntoInternalError};
8 8 use giterated_models::message::GiteratedMessage;
9 9 use giterated_models::object::NetworkAnyObject;
10 10 use giterated_models::operation::NetworkAnyOperation;
11 use giterated_models::settings::{GetSettingError, Setting};
11 use giterated_models::settings::{GetSettingError, Setting, SetSettingError};
12 12 use giterated_models::value::{GetValue, GiteratedObjectValue};
13 13 use giterated_models::{
14 14 error::OperationError,
@@ -366,7 +366,8 @@ impl GiteratedStack {
366 366 object_kind: &object_type,
367 367 setting_name: &operation.setting_name,
368 368 })
369 .unwrap();
369 // TODO: Check this
370 .ok_or(OperationError::Operation(serde_json::to_vec(&SetSettingError::InvalidSetting(operation.setting_name.clone(), object_type.clone())).as_internal_error()?))?;
370 371
371 372 let setting = (setting_meta.deserialize)(operation.value)
372 373 .as_internal_error_with_context(format!(