pksunkara / pgx_ulid

Postgres extension for ulid
MIT License
346 stars 21 forks source link

Use proper error code for input errors #50

Closed hlinnaka closed 3 months ago

hlinnaka commented 3 months ago

Before this commit, the error was reported with ERRCODE_INTERNAL_ERROR (SQLSTATE XX000):

postgres=# \set VERBOSITY verbose
postgres=# select 'foo'::ulid;
ERROR:  XX000: invalid input syntax for type ulid: "foo": invalid length
LINE 1: select 'foo'::ulid;
               ^
LOCATION:  lib.rs:37

With this, ERRCODE_INVALID_TEXT_REPRESENTATION (SQLSTATE 22P02) is used:

postgres=# \set VERBOSITY verbose
postgres=# select 'foo'::ulid;
ERROR:  22P02: invalid input syntax for type ulid: "foo": invalid length
LINE 1: select 'foo'::ulid;
               ^
LOCATION:  <ulid::ulid as pgrx::inoutfuncs::InOutFuncs>::input, lib.rs:39