I have stumbled across some unexpected behaviour in spray-json when a 
DeserializationException is thrown.

I've put together a minimal test app and tests in github here 
<https://github.com/rachelwilson/akka-json-override> using only simple 
classes and akka's latest akka-http-spray-json-experimental dependency in 
order to isolate the issue I'm having.  The tests and classes demonstrate 
the following:

(a) If a DeserializationException is thrown when deserialising a nested 
Json object, I notice the message of the thrown exception actually relates 
to the root object, not the object with the problem.  See the second test 
in RethowingExceptionSpec.  I realised this only when building this example 
app to demonstrate to my real problem which is....

(b) See the third test in RethowingExceptionSpec.  I would like to 
intercept the DeserializationException thrown by ProductFormats.fromField, 
handle a further special case, and if not my special case then rethrow the 
exception again.  However, if I rethrow the DeserializationException the 
same way as the original fromField method does, then my overridden 
fromField method doesnt terminate with the exception but instead appears to 
complete successfully.  This is despite the fact that in debug mode I can 
see the catch statement successfully calling deserialisationError() in 
spray-json's code.  I would expect the exception be thrown though because 
DeserializationException is a RuntimeException.  This behaviour is the same 
even if i throw a new DeserializationException "directly" in the catch 
statement of my overridden method.  But if i throw *any* other 
RuntimeException in the catch statement then the overriden fromField method 
*does* exit and the exception is thrown as expected (and with the correct 
message).

Is something somewhere swallowing DeserializationExceptions?

When I trace the execution and calls to fromField and 
deserialisationError() in debug it looks like the recursive call of 
fromField might be the reason for the final exception's message.  But I 
can't see anywhere in spray-json's code where the DeserializationException 
is being swallowed.

Whilst I can now achieve what I need to by throwing my own 
runtimeexception, but I'm extremely interested to know why I can't throw 
DeserializationExceptions from my own code?

Thank you for helping with my ongoing education :)

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to