alevy / postgresql-orm

An Haskell ORM (Object Relational Mapping) and migrations DSL for PostgreSQL.
http://simple.cx
GNU General Public License v3.0
78 stars 12 forks source link

Fail with Prelude.fail in FromJSON instances #33

Closed enobayram closed 3 years ago

enobayram commented 3 years ago

Failing with error causes an exception to be thrown while decoding the value, as opposed to a nice error message with a JSON path when the parser fails with Prelude.fail.

Before:

$ eitherDecode "true" :: Either String DBKey
*** Exception: Expected Number or Null
CallStack (from HasCallStack):
  error, called at .../postgresql-orm/src/Database/PostgreSQL/ORM/Model.hs:169:17 in main:Database.PostgreSQL.ORM.Model

With this PR:

$ eitherDecode "true" :: Either String DBKey
Left "Error in $: Expected Number or Null"

Note that the issue isn't just the error message, the exception is usually very unexpected coming out of JSON decoding.

alevy commented 3 years ago

@enobayram why did you close this?

enobayram commented 3 years ago

@alevy oops, didn't intend to close it, must've been a misclick.