beacon-biosignals / Legolas.jl

Tables.jl-friendly mechanisms for constructing, reading, writing, and validating Arrow tables against extensible, versioned, user-specified schemas.
Other
24 stars 2 forks source link

Print all schema violations in `validate`'s error message #85

Closed hannahilea closed 1 year ago

hannahilea commented 1 year ago

Close #56.

# Setup
using Legolas
using Legolas: SchemaVersion, @schema, @version
using Tables

@schema "foo" Foo
@version FooV1 begin
    a::Vector
    b::AbstractString
    c::Int32
    d::Int32
end
f = FooV1SchemaVersion()
t = Tables.Schema((:a, :b), (Int32, Float64))
Legolas.validate(t, f)

main:

julia> Legolas.validate(t, f)
ERROR: ArgumentError: field `a` has unexpected type; expected <:Vector, found Int32
Stacktrace:
 [1] validate(ts::Tables.Schema{(:a, :b), Tuple{Int32, Float64}}, sv::SchemaVersion{:foo, 1})
   @ Legolas ~/Code/Legolas.jl/src/schemas.jl:285
 [2] top-level scope
   @ REPL[8]:1

This branch:

julia> Legolas.validate(t, f)
ERROR: ArgumentError: Tables.Schema violates Legolas schema `foo@1`:
 - Could not find required field: `c`
 - Could not find required field: `d`
 - Incorrect type: `a` expected `<:Vector`, found `Int32`
 - Incorrect type: `b` expected `<:AbstractString`, found `Float64`
Provided Tables.Schema:
 :a  Int32
 :b  Float64

(Note: was updated following review feedback below)


Punch list: