Finally returning to this...
> Hm, class 42 is generally meant for SQL-level syntax errors. Are these > errors not coming from subroutines of hstore_in()? I think our usual > convention is to use ERRCODE_INVALID_TEXT_REPRESENTATION for complaints > that a data value does not meet its type's conventions. In any case > it seems closer to class 22 than 42. > I see, thanks for pointing that out. That seems like a useful distinction to preserve. I've updated it to ERRCODE_INVALID_TEXT_REPRESENTATION accordingly. These seem to have multiple problems, starting with incorrect > capitalization and extending to failure to quote the whole string > being complained of. I've modified the messages to comply with the guidelines, with a little help from a colleague who actually knows C. I'm attaching a revised patch; please let me know if there are any other issues before I submit to the commitfest. Best, Sherrylyn
diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c index 0c1d99a..4ee3d05 100644 --- a/contrib/hstore/hstore_io.c +++ b/contrib/hstore/hstore_io.c @@ -81,7 +81,10 @@ get_val(HSParser *state, bool ignoreeq, bool *escaped) } else if (*(state->ptr) == '=' && !ignoreeq) { - elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int32) (state->ptr - state->begin)); + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + (errmsg("syntax error at position %d: \"%s\"", + (int32) (state->ptr - state->begin), state->begin)))); } else if (*(state->ptr) == '\\') { @@ -138,7 +141,9 @@ get_val(HSParser *state, bool ignoreeq, bool *escaped) } else if (*(state->ptr) == '\0') { - elog(ERROR, "Unexpected end of string"); + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + (errmsg("unexpected end of string: \"%s\"", state->begin)))); } else { @@ -150,7 +155,9 @@ get_val(HSParser *state, bool ignoreeq, bool *escaped) else if (st == GV_WAITESCIN) { if (*(state->ptr) == '\0') - elog(ERROR, "Unexpected end of string"); + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + (errmsg("unexpected end of string: \"%s\"", state->begin)))); RESIZEPRSBUF; *(state->cur) = *(state->ptr); state->cur++; @@ -159,14 +166,16 @@ get_val(HSParser *state, bool ignoreeq, bool *escaped) else if (st == GV_WAITESCESCIN) { if (*(state->ptr) == '\0') - elog(ERROR, "Unexpected end of string"); + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + (errmsg("unexpected end of string: \"%s\"", state->begin)))); RESIZEPRSBUF; *(state->cur) = *(state->ptr); state->cur++; st = GV_INESCVAL; } else - elog(ERROR, "Unknown state %d at position line %d in file '%s'", st, __LINE__, __FILE__); + elog(ERROR, "unknown state %d at position line %d in file \"%s\"", st, __LINE__, __FILE__); state->ptr++; } @@ -216,11 +225,16 @@ parse_hstore(HSParser *state) } else if (*(state->ptr) == '\0') { - elog(ERROR, "Unexpected end of string"); + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + (errmsg("unexpected end of string: \"%s\"", state->begin)))); } else if (!isspace((unsigned char) *(state->ptr))) { - elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int32) (state->ptr - state->begin)); + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + (errmsg("syntax error at position %d: \"%s\"", + (int32) (state->ptr - state->begin), state->begin)))); } } else if (st == WGT) @@ -231,17 +245,24 @@ parse_hstore(HSParser *state) } else if (*(state->ptr) == '\0') { - elog(ERROR, "Unexpected end of string"); + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + (errmsg("unexpected end of string: \"%s\"", state->begin)))); } else { - elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int32) (state->ptr - state->begin)); + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + (errmsg("syntax error at position %d: \"%s\"", + (int32) (state->ptr - state->begin), state->begin)))); } } else if (st == WVAL) { if (!get_val(state, true, &escaped)) - elog(ERROR, "Unexpected end of string"); + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + (errmsg("unexpected end of string: \"%s\"", state->begin)))); state->pairs[state->pcur].val = state->word; state->pairs[state->pcur].vallen = hstoreCheckValLen(state->cur - state->word); state->pairs[state->pcur].isnull = false; @@ -268,11 +289,14 @@ parse_hstore(HSParser *state) } else if (!isspace((unsigned char) *(state->ptr))) { - elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int32) (state->ptr - state->begin)); + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + (errmsg("syntax error at position %d: \"%s\"", + (int32) (state->ptr - state->begin), state->begin)))); } } else - elog(ERROR, "Unknown state %d at line %d in file '%s'", st, __LINE__, __FILE__); + elog(ERROR, "unknown state %d at line %d in file \"%s\"", st, __LINE__, __FILE__); state->ptr++; }
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers