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++; }