Should Reads compose and andThen repath?

(Jason Pickens) #1

I had raised play-json/issues/171 when I discovered some rather surprising error messages when composing Reads using andThen.

The thing to discuss here is whether or not andThen and compose should use repath, effectively concatenating the paths of both Reads.

One example of where it doesn’t make sense to do so is if we start with:

  "a": 1,
  "b": 2,
  "c": 3

Now we read it with:

(__ \ 'a).json.prune andThen (__ \ 'b).json.prune andThen (__ \ 'd).json.pick

Of course this will fail since /d does not exist but what you get is:


The path in the error is messed up. What happened is that the intermediate success of the two prunes actually concatenated the paths of the very things they removed.

The only time when it would make sense to repath is when the first Reads has traversed down the tree and not retained anything that it traversed such as a pick or possibly a copyFrom.

I have since replaced all uses of andThen and compose with custom versions that keep the path unchanged.