The hstore module uses elog() to default to ERRCODE_INTERNAL_ERROR (SQLSTATE XX000) when the error message reads "Syntax error near '%c' at position %d".
I propose to switch to ereport() to return ERRCODE_SYNTAX_ERROR (SQLSTATE 42601), on the grounds that it's more transparent. It took me longer to figure out what error code was being returned than to write both the patch and my originally intended function using the patch.
I also propose to raise the same error code for "Unexpected end of string" in hstore, since it serves the same purpose, at least in my mind: differentiating between valid and invalid hstore syntax.
Any objections to my submitting the attached patch to the September commitfest?