@@ -10,9 +10,10 @@ use serde::Serialize;
1010use serde_json:: Value ;
1111use std:: ops:: { Deref , DerefMut } ;
1212
13+ use crate :: errors:: ExtractionError ;
1314use crate :: path:: Path ;
1415use crate :: system:: { FromSystem , System } ;
15- use crate :: task:: { Context , Effect , Error , InputError , IntoResult , UnexpectedError } ;
16+ use crate :: task:: { Context , Effect , Error , IntoResult } ;
1617
1718/// Extracts a pointer to a sub-element of the global state indicated
1819/// by the path.
@@ -75,7 +76,7 @@ impl<T> Pointer<T> {
7576}
7677
7778impl < T : DeserializeOwned > FromSystem for Pointer < T > {
78- type Error = InputError ;
79+ type Error = ExtractionError ;
7980
8081 fn from_system ( system : & System , context : & Context ) -> Result < Self , Self :: Error > {
8182 let json_ptr = context. path . as_ref ( ) ;
@@ -180,9 +181,10 @@ impl<T: Serialize> IntoResult<Patch> for Pointer<T> {
180181 fn into_result ( self ) -> Result < Patch , Error > {
181182 let before = self . initial ;
182183 let after = if let Some ( state) = self . state {
183- serde_json:: to_value ( state)
184- . with_context ( || "Failed to serialize pointer value" )
185- . map_err ( UnexpectedError :: from) ?
184+ // This should not happen unless there is a bug (hopefully).
185+ // if this happens during worker operation, it will be catched
186+ // as a panic in the task
187+ serde_json:: to_value ( state) . expect ( "failed to serialize pointer value" )
186188 } else {
187189 Value :: Null
188190 } ;
@@ -210,14 +212,6 @@ impl<T, E> From<Pointer<T>> for Effect<Pointer<T>, E> {
210212 }
211213}
212214
213- // Allow tasks to return a pointer
214- // This converts the pointer into a pure effect
215- impl < T : Serialize > From < Pointer < T > > for Effect < Patch , Error > {
216- fn from ( ptr : Pointer < T > ) -> Effect < Patch , Error > {
217- Effect :: from_result ( ptr. into_result ( ) )
218- }
219- }
220-
221215/// Extracts a sub-element of a state S as indicated by
222216/// a path.
223217///
@@ -227,7 +221,7 @@ impl<T: Serialize> From<Pointer<T>> for Effect<Patch, Error> {
227221pub struct View < T > ( Pointer < T > ) ;
228222
229223impl < T : DeserializeOwned > FromSystem for View < T > {
230- type Error = InputError ;
224+ type Error = ExtractionError ;
231225
232226 fn from_system ( system : & System , context : & Context ) -> Result < Self , Self :: Error > {
233227 let pointer = Pointer :: < T > :: from_system ( system, context) ?;
@@ -269,14 +263,6 @@ impl<T, E> From<View<T>> for Effect<View<T>, E> {
269263 }
270264}
271265
272- // Allow tasks to return a view
273- // This converts the view into a pure effect
274- impl < T : Serialize > From < View < T > > for Effect < Patch , Error > {
275- fn from ( view : View < T > ) -> Effect < Patch , Error > {
276- Effect :: from_result ( view. into_result ( ) )
277- }
278- }
279-
280266#[ cfg( test) ]
281267mod tests {
282268 use super :: * ;
0 commit comments