bowbahdoe/json

Investigate situations where JsonDecodeException might give a wrong result for path

bowbahdoe opened this issue · 1 comments

Technically speaking, we could end up with an incorrect "path" recorded in a JsonDecodeException if someone escapes the decoder mechanism.

For instance.

Json j = Json.readString("""
    {
      "a": [
         {
            "b": 123
         }
      ]
    }
""");

List<String> b = JsonDecoder.field(j, "a", a -> {
    var array = JsonDecoder.array(a);
    return array.stream()
        .map(JsonDecoder::string)
        .toList();
} 

This would record the path as a.b not a.[0].b. There might not be a nice way to account for this in general, at least without propagating metadata to the actual Json forms.

Maybe metadata is valid to propagate though! There could be more uses.

Idea that popped in my head this night - If extent locals really are cheap enough, we could mark "trusted contexts" where we know that all accesses have a matching throw atIndex/atField and know that those add to the path, representing "untrusted contexts" in a different way that isn't "this error definitely occurred at this path".

Bit unsure of the shape of that atm, but its one idea