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

ambee/giterated

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

Add `AuthorizedOperation`

Implement `AuthorizedOperation` for `RegisterAccountRequest`, `AuthenticationTokenRequest`, `RepositoryCreateRequest`, Implement `FromOperationState` for `AuthorizedUser` and `AuthorizedInstance`, depending on the operation being `AuthorizedOperation<Object>`

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨1dcec18

⁨giterated-stack/src/lib.rs⁩ - ⁨23994⁩ bytes
Raw
1 pub mod handler;
2 pub mod state;
3
4 use std::{collections::HashMap, future::Future, ops::Deref, pin::Pin, str::FromStr, sync::Arc};
5
6 use futures_util::FutureExt;
7 use giterated_models::{
8 error::OperationError,
9 instance::{
10 AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest,
11 },
12 object::{
13 AnyObject, GiteratedObject, Object, ObjectRequest, ObjectRequestError, ObjectResponse,
14 },
15 object_backend::ObjectBackend,
16 operation::{AnyOperation, GiteratedOperation},
17 repository::Repository,
18 user::User,
19 };
20 use handler::GiteratedBackend;
21 use serde::{de::DeserializeOwned, Serialize};
22 use serde_json::Value;
23 use state::HandlerState;
24 use tokio::{sync::mpsc::channel, task::JoinHandle};
25 use tracing::{error, warn};
26
27 #[derive(Clone, Debug, Hash, Eq, PartialEq)]
28 struct ObjectOperationPair {
29 object_name: String,
30 operation_name: String,
31 }
32
33 pub struct OperationHandlers<S: Send + Sync + Clone> {
34 operations: HashMap<ObjectOperationPair, OperationWrapper<S>>,
35 get_object: Vec<OperationWrapper<S>>,
36 }
37
38 impl<S: Send + Sync + Clone> Default for OperationHandlers<S> {
39 fn default() -> Self {
40 Self {
41 operations: HashMap::new(),
42 get_object: Vec::new(),
43 }
44 }
45 }
46
47 impl<S: Send + Sync + Clone + 'static> OperationHandlers<S> {
48 pub fn insert<
49 A,
50 O: GiteratedObject + Send + Sync,
51 D: GiteratedOperation<O> + 'static,
52 H: GiteratedOperationHandler<A, O, D, S> + Send + Sync + 'static + Clone,
53 >(
54 &mut self,
55 handler: H,
56 ) -> &mut Self {
57 let object_name = handler.object_name().to_string();
58 let operation_name = handler.operation_name().to_string();
59
60 let wrapped = OperationWrapper::new(handler);
61
62 let pair = ObjectOperationPair {
63 object_name,
64 operation_name,
65 };
66
67 assert!(self.operations.insert(pair, wrapped).is_none());
68
69 self
70 }
71
72 pub fn register_object<O: GiteratedObject + Send + Sync>(&mut self) -> &mut Self {
73 let closure = |_: &Instance, operation: ObjectRequest, _state| {
74 async move {
75 if O::from_str(&operation.0).is_ok() {
76 Ok(ObjectResponse(operation.0))
77 } else {
78 Err(OperationError::Unhandled)
79 }
80 }
81 .boxed()
82 };
83
84 let wrapped = OperationWrapper::new(closure);
85
86 self.get_object.push(wrapped);
87
88 self
89 }
90
91 pub async fn handle<O: GiteratedObject>(
92 &self,
93 object: &O,
94 operation_name: &str,
95 operation: AnyOperation,
96 state: S,
97 operation_state: &StackOperationState,
98 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
99 // TODO
100 let object = object.to_string();
101
102 let object_name = {
103 if User::from_str(&object).is_ok() {
104 User::object_name()
105 } else if Repository::from_str(&object).is_ok() {
106 Repository::object_name()
107 } else if Instance::from_str(&object).is_ok() {
108 Instance::object_name()
109 } else {
110 return Err(OperationError::Unhandled);
111 }
112 }
113 .to_string();
114
115 let target_handler = ObjectOperationPair {
116 object_name,
117 operation_name: operation_name.to_string(),
118 };
119
120 if let Some(handler) = self.operations.get(&target_handler) {
121 handler
122 .handle(
123 AnyObject(object.to_string()),
124 operation.clone(),
125 state.clone(),
126 operation_state,
127 )
128 .await
129 } else {
130 Err(OperationError::Unhandled)
131 }
132 }
133
134 pub async fn resolve_object(
135 &self,
136 instance: AnyObject,
137 request: ObjectRequest,
138 state: S,
139 operation_state: &StackOperationState,
140 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
141 for handler in self.get_object.iter() {
142 if let Ok(response) = handler
143 .handle(
144 instance.clone(),
145 AnyOperation(serde_json::to_value(request.clone()).unwrap()),
146 state.clone(),
147 operation_state,
148 )
149 .await
150 {
151 return Ok(response);
152 }
153 }
154
155 Err(OperationError::Unhandled)
156 }
157 }
158
159 #[async_trait::async_trait]
160 pub trait GiteratedOperationHandler<
161 L,
162 O: GiteratedObject,
163 D: GiteratedOperation<O>,
164 S: Send + Sync + Clone,
165 >
166 {
167 fn operation_name(&self) -> &str;
168 fn object_name(&self) -> &str;
169
170 async fn handle(
171 &self,
172 object: &O,
173 operation: D,
174 state: S,
175 operation_state: &StackOperationState,
176 ) -> Result<D::Success, OperationError<D::Failure>>;
177 }
178
179 #[async_trait::async_trait]
180 impl<O, D, F, S> GiteratedOperationHandler<(), O, D, S> for F
181 where
182 F: FnMut(
183 &O,
184 D,
185 S,
186 ) -> Pin<
187 Box<dyn Future<Output = Result<D::Success, OperationError<D::Failure>>> + Send>,
188 > + Send
189 + Sync
190 + Clone,
191 O: GiteratedObject + Send + Sync,
192 D: GiteratedOperation<O> + 'static,
193 <D as GiteratedOperation<O>>::Failure: Send,
194 S: Send + Sync + Clone + 'static,
195 {
196 fn operation_name(&self) -> &str {
197 D::operation_name()
198 }
199
200 fn object_name(&self) -> &str {
201 O::object_name()
202 }
203
204 async fn handle(
205 &self,
206 object: &O,
207 operation: D,
208 state: S,
209 _operation_state: &StackOperationState,
210 ) -> Result<D::Success, OperationError<D::Failure>> {
211 self.clone()(object, operation, state).await
212 }
213 }
214
215 #[async_trait::async_trait]
216 impl<O, O1, D, F, S> GiteratedOperationHandler<(O1,), O, D, S> for F
217 where
218 F: FnMut(
219 &O,
220 D,
221 S,
222 O1,
223 ) -> Pin<
224 Box<dyn Future<Output = Result<D::Success, OperationError<D::Failure>>> + Send>,
225 > + Send
226 + Sync
227 + Clone,
228 O: GiteratedObject + Send + Sync,
229 D: GiteratedOperation<O> + 'static + Send + Sync,
230 <D as GiteratedOperation<O>>::Failure: Send,
231 S: Send + Sync + Clone + 'static,
232 O1: FromOperationState<O, D>,
233 {
234 fn operation_name(&self) -> &str {
235 D::operation_name()
236 }
237
238 fn object_name(&self) -> &str {
239 O::object_name()
240 }
241
242 async fn handle(
243 &self,
244 object: &O,
245 operation: D,
246 state: S,
247 operation_state: &StackOperationState,
248 ) -> Result<D::Success, OperationError<D::Failure>> {
249 let o1 = O1::from_state(object, &operation, operation_state)
250 .await
251 .map_err(|e| OperationError::Internal(e.to_string()))?;
252 self.clone()(object, operation, state, o1).await
253 }
254 }
255
256 #[async_trait::async_trait]
257 impl<O, O1, O2, D, F, S> GiteratedOperationHandler<(O1, O2), O, D, S> for F
258 where
259 F: FnMut(
260 &O,
261 D,
262 S,
263 O1,
264 O2,
265 ) -> Pin<
266 Box<dyn Future<Output = Result<D::Success, OperationError<D::Failure>>> + Send>,
267 > + Send
268 + Sync
269 + Clone,
270 O: GiteratedObject + Send + Sync,
271 D: GiteratedOperation<O> + 'static + Send + Sync,
272 <D as GiteratedOperation<O>>::Failure: Send,
273 S: Send + Sync + Clone + 'static,
274 O1: FromOperationState<O, D>,
275 O2: FromOperationState<O, D>,
276 {
277 fn operation_name(&self) -> &str {
278 D::operation_name()
279 }
280
281 fn object_name(&self) -> &str {
282 O::object_name()
283 }
284
285 async fn handle(
286 &self,
287 object: &O,
288 operation: D,
289 state: S,
290 operation_state: &StackOperationState,
291 ) -> Result<D::Success, OperationError<D::Failure>> {
292 let o1 = O1::from_state(object, &operation, operation_state)
293 .await
294 .map_err(|e| OperationError::Internal(e.to_string()))?;
295 let o2 = O2::from_state(object, &operation, operation_state)
296 .await
297 .map_err(|e| OperationError::Internal(e.to_string()))?;
298 self.clone()(object, operation, state, o1, o2).await
299 }
300 }
301
302 #[async_trait::async_trait]
303 impl<O, O1, O2, O3, D, F, S> GiteratedOperationHandler<(O1, O2, O3), O, D, S> for F
304 where
305 F: FnMut(
306 &O,
307 D,
308 S,
309 O1,
310 O2,
311 O3,
312 ) -> Pin<
313 Box<dyn Future<Output = Result<D::Success, OperationError<D::Failure>>> + Send>,
314 > + Send
315 + Sync
316 + Clone,
317 O: GiteratedObject + Send + Sync,
318 D: GiteratedOperation<O> + 'static + Send + Sync,
319 <D as GiteratedOperation<O>>::Failure: Send,
320 S: Send + Sync + Clone + 'static,
321 O1: FromOperationState<O, D>,
322 O2: FromOperationState<O, D>,
323 O3: FromOperationState<O, D>,
324 {
325 fn operation_name(&self) -> &str {
326 D::operation_name()
327 }
328
329 fn object_name(&self) -> &str {
330 O::object_name()
331 }
332
333 async fn handle(
334 &self,
335 object: &O,
336 operation: D,
337 state: S,
338 operation_state: &StackOperationState,
339 ) -> Result<D::Success, OperationError<D::Failure>> {
340 let o1 = O1::from_state(object, &operation, operation_state)
341 .await
342 .map_err(|e| OperationError::Internal(e.to_string()))?;
343 let o2 = O2::from_state(object, &operation, operation_state)
344 .await
345 .map_err(|e| OperationError::Internal(e.to_string()))?;
346 let o3 = O3::from_state(object, &operation, operation_state)
347 .await
348 .map_err(|e| OperationError::Internal(e.to_string()))?;
349 self.clone()(object, operation, state, o1, o2, o3).await
350 }
351 }
352
353 pub struct OperationWrapper<S: Send + Sync + Clone> {
354 func: Box<
355 dyn Fn(
356 AnyObject,
357 AnyOperation,
358 S,
359 StackOperationState,
360 )
361 -> Pin<Box<dyn Future<Output = Result<Vec<u8>, OperationError<Vec<u8>>>> + Send>>
362 + Send
363 + Sync,
364 >,
365 object_name: String,
366 }
367
368 impl<S: Send + Sync + Clone + 'static> OperationWrapper<S> {
369 pub fn new<
370 A,
371 O: GiteratedObject + Send + Sync,
372 D: GiteratedOperation<O> + 'static,
373 F: GiteratedOperationHandler<A, O, D, S> + Send + Sync + 'static + Clone,
374 >(
375 handler: F,
376 ) -> Self {
377 let handler = Arc::new(Box::pin(handler));
378 Self {
379 func: Box::new(move |any_object, any_operation, state, operation_state| {
380 let handler = handler.clone();
381 async move {
382 let handler = handler.clone();
383 let object: O =
384 O::from_object_str(&any_object.0).map_err(|_| OperationError::Unhandled)?;
385 let operation: D = serde_json::from_value(any_operation.0.clone())
386 .map_err(|_| OperationError::Unhandled)?;
387
388 let result = handler
389 .handle(&object, operation, state, &operation_state)
390 .await;
391 result
392 .map(|success| serde_json::to_vec(&success).unwrap())
393 .map_err(|err| match err {
394 OperationError::Operation(err) => {
395 OperationError::Operation(serde_json::to_vec(&err).unwrap())
396 }
397 OperationError::Internal(internal) => {
398 OperationError::Internal(internal)
399 }
400 OperationError::Unhandled => OperationError::Unhandled,
401 })
402 }
403 .boxed()
404 }),
405 object_name: O::object_name().to_string(),
406 }
407 }
408
409 async fn handle(
410 &self,
411 object: AnyObject,
412 operation: AnyOperation,
413 state: S,
414 operation_state: &StackOperationState,
415 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
416 (self.func)(object, operation, state, operation_state.clone()).await
417 }
418 }
419
420 #[async_trait::async_trait]
421 pub trait FromOperationState<O: GiteratedObject, D: GiteratedOperation<O> + Send + Sync>:
422 Sized + Clone + Send
423 {
424 type Error: Serialize + DeserializeOwned;
425
426 async fn from_state(
427 object: &O,
428 operation: &D,
429 state: &StackOperationState,
430 ) -> Result<Self, OperationError<Self::Error>>;
431 }
432
433 #[async_trait::async_trait]
434 impl<O: GiteratedObject, D: GiteratedOperation<O> + Send + Sync> FromOperationState<O, D>
435 for BackendWrapper
436 {
437 type Error = ();
438
439 async fn from_state(
440 _object: &O,
441 _operation: &D,
442 state: &StackOperationState,
443 ) -> Result<Self, OperationError<()>> {
444 Ok(state.giterated_backend.clone())
445 }
446 }
447
448 #[async_trait::async_trait]
449 impl<O: GiteratedObject, D: GiteratedOperation<O> + Send + Sync> FromOperationState<O, D>
450 for StackOperationState
451 {
452 type Error = ();
453
454 async fn from_state(
455 _object: &O,
456 _operation: &D,
457 state: &StackOperationState,
458 ) -> Result<StackOperationState, OperationError<()>> {
459 Ok(state.clone())
460 }
461 }
462
463 #[async_trait::async_trait]
464 impl<O: GiteratedObject, D: GiteratedOperation<O> + Send + Sync> FromOperationState<O, D>
465 for AuthenticatedUser
466 {
467 type Error = ();
468
469 async fn from_state(
470 _object: &O,
471 _operation: &D,
472 state: &StackOperationState,
473 ) -> Result<AuthenticatedUser, OperationError<()>> {
474 state
475 .user
476 .clone()
477 .ok_or_else(|| OperationError::Operation(()))
478 }
479 }
480
481 #[async_trait::async_trait]
482 impl<O: GiteratedObject, D: GiteratedOperation<O> + Send + Sync> FromOperationState<O, D>
483 for AuthenticatedInstance
484 {
485 type Error = ();
486
487 async fn from_state(
488 _object: &O,
489 _operation: &D,
490 state: &StackOperationState,
491 ) -> Result<AuthenticatedInstance, OperationError<()>> {
492 state
493 .instance
494 .clone()
495 .ok_or_else(|| OperationError::Operation(()))
496 }
497 }
498
499 #[async_trait::async_trait]
500 impl<
501 T: FromOperationState<O, D> + Send + Sync,
502 O: GiteratedObject + Sync,
503 D: GiteratedOperation<O> + Send + Sync,
504 > FromOperationState<O, D> for Option<T>
505 {
506 type Error = ();
507
508 async fn from_state(
509 object: &O,
510 operation: &D,
511 state: &StackOperationState,
512 ) -> Result<Option<T>, OperationError<()>> {
513 Ok(T::from_state(object, operation, state).await.ok())
514 }
515 }
516
517 #[derive(Clone)]
518 pub struct AuthorizedUser(AuthenticatedUser);
519
520 #[derive(Clone)]
521 pub struct AuthorizedInstance(AuthenticatedInstance);
522
523 #[async_trait::async_trait]
524 pub trait AuthorizedOperation<O: GiteratedObject>: GiteratedOperation<O> {
525 async fn authorize(
526 &self,
527 authorize_for: &O,
528 state: &StackOperationState,
529 ) -> Result<bool, OperationError<()>>;
530 }
531
532 #[async_trait::async_trait]
533 impl AuthorizedOperation<Instance> for RegisterAccountRequest {
534 async fn authorize(
535 &self,
536 authorize_for: &Instance,
537 state: &StackOperationState,
538 ) -> Result<bool, OperationError<()>> {
539 if state.our_instance == *authorize_for {
540 Ok(true)
541 } else {
542 Ok(false)
543 }
544 }
545 }
546
547 #[async_trait::async_trait]
548 impl AuthorizedOperation<Instance> for AuthenticationTokenRequest {
549 async fn authorize(
550 &self,
551 authorize_for: &Instance,
552 state: &StackOperationState,
553 ) -> Result<bool, OperationError<()>> {
554 if state.our_instance == *authorize_for {
555 Ok(true)
556 } else {
557 Ok(false)
558 }
559 }
560 }
561
562 #[async_trait::async_trait]
563 impl AuthorizedOperation<Instance> for RepositoryCreateRequest {
564 async fn authorize(
565 &self,
566 authorize_for: &Instance,
567 state: &StackOperationState,
568 ) -> Result<bool, OperationError<()>> {
569 if state.our_instance == *authorize_for {
570 Ok(true)
571 } else {
572 Ok(false)
573 }
574 }
575 }
576
577 #[async_trait::async_trait]
578 impl<A: AuthorizedOperation<User> + Send + Sync> FromOperationState<User, A> for AuthorizedUser {
579 type Error = ();
580
581 async fn from_state(
582 object: &User,
583 operation: &A,
584 state: &StackOperationState,
585 ) -> Result<AuthorizedUser, OperationError<()>> {
586 let authenticated = AuthenticatedUser::from_state(object, operation, state).await?;
587
588 match operation.authorize(object, state).await {
589 Ok(authorized) => {
590 assert!(authorized);
591 }
592 Err(err) => return Err(OperationError::Internal(err.to_string())),
593 };
594
595 Ok(AuthorizedUser(authenticated))
596 }
597 }
598
599 #[async_trait::async_trait]
600 impl<A: AuthorizedOperation<Instance> + Send + Sync> FromOperationState<Instance, A>
601 for AuthorizedInstance
602 {
603 type Error = ();
604
605 async fn from_state(
606 object: &Instance,
607 operation: &A,
608 state: &StackOperationState,
609 ) -> Result<AuthorizedInstance, OperationError<()>> {
610 let authenticated = AuthenticatedInstance::from_state(object, operation, state).await?;
611
612 match operation.authorize(object, state).await {
613 Ok(authorized) => {
614 assert!(authorized);
615 }
616 Err(err) => return Err(OperationError::Internal(err.to_string())),
617 };
618
619 Ok(AuthorizedInstance(authenticated))
620 }
621 }
622
623 // #[async_trait::async_trait> FromOperationState for Option<T> {
624 // type Error = ();
625
626 // async fn from_state(state: &StackOperationState) -> Result<Option<T>, OperationError<()>> {
627 // Ok(T::from_state(]
628 // impl<T: FromOperationStatestate).await.ok())
629 // }
630 // }
631
632 #[derive(Clone)]
633 pub struct StackOperationState {
634 pub our_instance: Instance,
635 pub giterated_backend: BackendWrapper,
636 pub instance: Option<AuthenticatedInstance>,
637 pub user: Option<AuthenticatedUser>,
638 }
639
640 #[derive(Clone, Debug)]
641 pub struct AuthenticatedInstance(Instance);
642
643 impl AuthenticatedInstance {
644 pub fn new(instance: Instance) -> Self {
645 AuthenticatedInstance(instance)
646 }
647 }
648
649 impl Deref for AuthenticatedInstance {
650 type Target = Instance;
651
652 fn deref(&self) -> &Self::Target {
653 &self.0
654 }
655 }
656
657 #[derive(Clone, Debug)]
658 pub struct AuthenticatedUser(User);
659
660 impl AuthenticatedUser {
661 pub fn new(user: User) -> Self {
662 AuthenticatedUser(user)
663 }
664 }
665
666 impl Deref for AuthenticatedUser {
667 type Target = User;
668
669 fn deref(&self) -> &Self::Target {
670 &self.0
671 }
672 }
673
674 #[derive(Clone)]
675 pub struct BackendWrapper {
676 sender: tokio::sync::mpsc::Sender<(
677 tokio::sync::oneshot::Sender<Result<Value, OperationError<Value>>>,
678 WrappedOperation,
679 )>,
680 task: Arc<JoinHandle<()>>,
681 }
682
683 pub struct WrappedOperation {
684 object: AnyObject,
685 operation_payload: AnyOperation,
686 operation_name: String,
687 state: StackOperationState,
688 }
689
690 impl BackendWrapper {
691 pub fn new<S: HandlerState>(backend: GiteratedBackend<S>) -> Self {
692 // Spawn listener task
693
694 let (send, mut recv) = channel::<(
695 tokio::sync::oneshot::Sender<Result<Value, OperationError<Value>>>,
696 WrappedOperation,
697 )>(1024);
698
699 let task = tokio::spawn(async move {
700 while let Some((responder, message)) = recv.recv().await {
701 let raw_result = backend
702 .object_operation(
703 message.object,
704 &message.operation_name,
705 message.operation_payload,
706 &message.state,
707 )
708 .await;
709
710 responder.send(raw_result).unwrap();
711 }
712 error!("Error, thing's dead");
713 });
714
715 Self {
716 sender: send,
717 task: Arc::new(task),
718 }
719 }
720
721 pub async fn call(&self, operation: WrappedOperation) -> Result<Value, OperationError<Value>> {
722 let (sender, response) = tokio::sync::oneshot::channel();
723
724 self.sender
725 .send((sender, operation))
726 .await
727 .map_err(|e| OperationError::Internal(e.to_string()))?;
728
729 match response.await {
730 Ok(result) => Ok(result?),
731 Err(err) => Err(OperationError::Internal(err.to_string())),
732 }
733 }
734 }
735
736 use std::fmt::Debug;
737
738 #[async_trait::async_trait]
739 impl ObjectBackend<StackOperationState> for BackendWrapper {
740 async fn object_operation<O, D>(
741 &self,
742 object: O,
743 operation: &str,
744 payload: D,
745 operation_state: &StackOperationState,
746 ) -> Result<D::Success, OperationError<D::Failure>>
747 where
748 O: GiteratedObject + Debug,
749 D: GiteratedOperation<O> + Debug,
750 {
751 let operation = WrappedOperation {
752 object: AnyObject(object.to_string()),
753 operation_name: operation.to_string(),
754 operation_payload: AnyOperation(serde_json::to_value(payload).unwrap()),
755 state: operation_state.clone(),
756 };
757
758 let raw_result = self.call(operation).await;
759
760 match raw_result {
761 Ok(result) => Ok(serde_json::from_value(result)
762 .map_err(|e| OperationError::Internal(e.to_string()))?),
763 Err(err) => match err {
764 OperationError::Internal(internal) => {
765 warn!(
766 "Internal Error: {:?}",
767 OperationError::<()>::Internal(internal.clone())
768 );
769
770 Err(OperationError::Internal(internal))
771 }
772 OperationError::Unhandled => Err(OperationError::Unhandled),
773 OperationError::Operation(err) => Err(OperationError::Operation(
774 serde_json::from_value(err)
775 .map_err(|e| OperationError::Internal(e.to_string()))?,
776 )),
777 },
778 }
779 }
780
781 async fn get_object<O: GiteratedObject + Debug>(
782 &self,
783 object_str: &str,
784 operation_state: &StackOperationState,
785 ) -> Result<Object<StackOperationState, O, Self>, OperationError<ObjectRequestError>> {
786 let operation = WrappedOperation {
787 object: AnyObject(object_str.to_string()),
788 operation_name: ObjectRequest::operation_name().to_string(),
789 operation_payload: AnyOperation(
790 serde_json::to_value(ObjectRequest(object_str.to_string())).unwrap(),
791 ),
792 state: operation_state.clone(),
793 };
794
795 let raw_result = self.call(operation).await;
796
797 let object: ObjectResponse = match raw_result {
798 Ok(result) => Ok(serde_json::from_value(result)
799 .map_err(|e| OperationError::Internal(e.to_string()))?),
800 Err(err) => match err {
801 OperationError::Internal(internal) => {
802 warn!(
803 "Internal Error: {:?}",
804 OperationError::<()>::Internal(internal.clone())
805 );
806
807 Err(OperationError::Internal(internal))
808 }
809 OperationError::Unhandled => Err(OperationError::Unhandled),
810 OperationError::Operation(err) => Err(OperationError::Operation(
811 serde_json::from_value(err)
812 .map_err(|e| OperationError::Internal(e.to_string()))?,
813 )),
814 },
815 }?;
816
817 unsafe {
818 Ok(Object::new_unchecked(
819 O::from_str(&object.0)
820 .map_err(|_| OperationError::Internal("deserialize failure".to_string()))?,
821 self.clone(),
822 ))
823 }
824 }
825 }
826