Hi hackers,

I noticed that setweight() reports an internal error (SQLSTATE XX000)
when the weight argument is not one of A/a, B/b, C/c, D/d, even though
the weight comes directly from user input.  The two-argument variant
also prints the weight as a raw ASCII code, which is a bit unfriendly:

    =# SELECT setweight('cat:1'::tsvector, 'p');
    ERROR:  unrecognized weight: 112

ts_filter() in the same file (tsvector_op.c) already handles the
equivalent case with ereport() and ERRCODE_INVALID_PARAMETER_VALUE,
so the attached patch simply makes tsvector_setweight() and
tsvector_setweight_by_filter() do the same, and adds regression tests
covering the three error paths (none of which were covered before).

This seems to be in the same spirit as the earlier cleanup of
user-reachable internal error codes [1]; these two sites appear to
have been missed there.

The patch is against the master and passes make check. Please let me know
if I've missed anything -- I'd be happy to revise.

[1] https://postgr.es/m/[email protected]

Best regards,
Ewan Young

Attachment: v1-0001-Use-ereport-not-elog-for-invalid-weights-in-setweight.patch
Description: Binary data

Reply via email to