taoensso / faraday

Amazon DynamoDB client for Clojure
https://www.taoensso.com/faraday
Eclipse Public License 1.0
238 stars 84 forks source link

Allow lazy sequences to be serialized as long as they have been realized #140

Closed joelittlejohn closed 4 years ago

joelittlejohn commented 4 years ago

Until now, including a lazy sequence in item data when serializing would result in an error like:

java.lang.IllegalArgumentException:
No implementation of method: :serialize of protocol: #'taoensso.faraday/ISerializable found for class: clojure.lang.LazySeq

This is a common failure scenario for new users of Faraday since we tend to create lazy sequences often when transforming data. There's discussion about what Faraday should do with these sequence here: https://github.com/Taoensso/faraday/issues/99.

This change allows a lazy sequence to be serialized and written as long as it has been realized. This seemed like the best compromise.

Closes #99

joelittlejohn commented 4 years ago

I originally planned to do two things here:

  1. Improve the error message when a lazy sequence is included in the item data
  2. Give more info about the path to the error, to make the lazy sequence easier to find

Whilst deciding how to phrase the message, I found it hard to justify to myself that lazy sequences that have been realized should still be rejected, so I ended up changing tack. I have improved the error message a lot for sequences that must be rejected. I do believe it's still right to reject sequences that could potentially be infinite.

Re including the 'path' to the data in the error message, I didn't end up attempting this because it required too much change all over the code base. Hopefully with a better description of the problem it will be more clear what to look for to solve it.