brandonchinn178 / aeson-schemas

Easily consume JSON data on-demand with type-safety
http://hackage.haskell.org/package/aeson-schemas
BSD 3-Clause "New" or "Revised" License
52 stars 1 forks source link

Pretty print schema in error messages #11

Open brandon-leapyear opened 4 years ago

brandon-leapyear commented 4 years ago

From the README:

<interactive>:1:6: error:
    • Key 'isEnabled' does not exist in the following schema:
      '[ '("id", 'Data.Aeson.Schema.SchemaInt),
         '("name", 'Data.Aeson.Schema.SchemaText),
         '("age",
           'Data.Aeson.Schema.SchemaMaybe 'Data.Aeson.Schema.SchemaInt),
         '("enabled", 'Data.Aeson.Schema.SchemaBool),
         '("groups",
           'Data.Aeson.Schema.SchemaMaybe
             ('Data.Aeson.Schema.SchemaList
                ('Data.Aeson.Schema.SchemaObject
                   '[ '("id", 'Data.Aeson.Schema.SchemaInt),
                      '("name", 'Data.Aeson.Schema.SchemaText)])))]
    • In the second argument of ‘(.)’, namely ‘getKey @"isEnabled"’
      In the first argument of ‘(<$:>)’, namely
        ‘(id . getKey @"isEnabled")’
      In the first argument of ‘(.)’, namely
        ‘((id . getKey @"isEnabled") <$:>)’

It would be nice to pretty print the schema in the error message, e.g.

<interactive>:1:6: error:
    • Key 'isEnabled' does not exist in the following schema:
      { id: Int,
        name: Text,
        age: Maybe Int,
        enabled: Bool,
        groups: Maybe List { id: Int, name: Text },
      }
    • In the second argument of ‘(.)’, namely ‘getKey @"isEnabled"’
      In the first argument of ‘(<$:>)’, namely
        ‘(id . getKey @"isEnabled")’
      In the first argument of ‘(.)’, namely
        ‘((id . getKey @"isEnabled") <$:>)’