Skip to content

v1.2.0

Choose a tag to compare

@passsy passsy released this 13 Oct 11:44
· 6 commits to main since this release
v1.2.0
b58afa4
  • Better error messages #64, especially for absent values

    PickException: expected a non-null value at shoes[0].name, but it is absent
    
      query   shoes[0].name
                       ~~~~ no such key
      at      shoes[0] = {"id": 42, "size": "M"}
      hint    Use asStringOrNull() when the value may be null/absent at some point (String?).
    

    A value that can't be parsed is shown with its type, and large values are shortened.

    PickException: could not parse an int at shoes[0].size
    
      query   shoes[0].size
      found   "M"  (a String)
    
  • New asJsonObjectOrThrow(), asJsonObjectOrEmpty() and asJsonObjectOrNull() return a Map<String, Object?> that goes straight into a fromJson function, no type arguments needed #70.
    Entries with a key that isn't a String are ignored.

  • New asJsonObjectListOrThrow(), asJsonObjectListOrEmpty() and asJsonObjectListOrNull() for a list of JSON objects #70.

    // before
    pick(json, 'users').asListOrEmpty((pick) => pick.asMapOrThrow<String, dynamic>());
    // after
    pick(json, 'users').asJsonObjectListOrEmpty();
  • New asMapListOrThrow<K, V>(), asMapListOrEmpty<K, V>() and asMapListOrNull<K, V>() for a list of maps with any key type #70.

  • Fix Pick.isAbsent is true below a null, however the path is written #64.
    pick({'a': null}, 'a', 'b').isAbsent was false, while pick({'a': null}, 'a')('b').isAbsent was true.

  • New PickException.fromPick(pick, 'expected a Timestamp') lets custom parsers throw errors like the built-in ones #64.

  • New Pick.redactValues() masks error values while keeping keys and types visible; Pick.redactsValues exposes the policy to custom parsers and RequiredPick.redactValues() preserves non-null chaining #65.

  • Fix as*OrThrow() and letOrThrow() no longer leave an internal _required_pick_error_hint entry in Pick.context.
    That also makes them as fast as their OrNull counterparts #68.

  • Deprecated Pick.path, Pick.missingValueAtIndex, Pick.followablePath and Pick.debugParsingExit.
    The error message of a PickException shows where a pick failed.
    A custom parser that built its message from them throws PickException.fromPick(this, 'expected a Foo') instead #69.