diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2003-07-24 17:52:50 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2003-07-24 17:52:50 +0000 |
| commit | 8fd5b3ed67d91937516d855bd6f225052aa88f2a (patch) | |
| tree | 5f14c30cb79692b6d35e612ed97feb79f62a155d /contrib/ltree | |
| parent | f0c5384d4a21d85198f86281f61d5754bfdca7a5 (diff) | |
| download | postgresql-8fd5b3ed67d91937516d855bd6f225052aa88f2a.tar.gz | |
Error message editing in contrib (mostly by Joe Conway --- thanks Joe!)
Diffstat (limited to 'contrib/ltree')
| -rw-r--r-- | contrib/ltree/_ltree_gist.c | 11 | ||||
| -rw-r--r-- | contrib/ltree/_ltree_op.c | 8 | ||||
| -rw-r--r-- | contrib/ltree/expected/ltree.out | 20 | ||||
| -rw-r--r-- | contrib/ltree/lquery_op.c | 4 | ||||
| -rw-r--r-- | contrib/ltree/ltree_gist.c | 15 | ||||
| -rw-r--r-- | contrib/ltree/ltree_io.c | 85 | ||||
| -rw-r--r-- | contrib/ltree/ltree_op.c | 4 | ||||
| -rw-r--r-- | contrib/ltree/ltxtquery_io.c | 40 |
8 files changed, 141 insertions, 46 deletions
diff --git a/contrib/ltree/_ltree_gist.c b/contrib/ltree/_ltree_gist.c index ec20067230..412fafa1ff 100644 --- a/contrib/ltree/_ltree_gist.c +++ b/contrib/ltree/_ltree_gist.c @@ -74,7 +74,9 @@ _ltree_compress(PG_FUNCTION_ARGS) ltree *item = (ltree *) ARR_DATA_PTR(val); if (ARR_NDIM(val) != 1) - elog(ERROR, "Dimension of array != 1"); + ereport(ERROR, + (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), + errmsg("array must be one-dimensional"))); key = (ltree_gist *) palloc(len); key->len = len; @@ -502,7 +504,9 @@ _arrq_cons(ltree_gist *key, ArrayType *_query) { int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query)); if (ARR_NDIM(_query) != 1) - elog(ERROR, "Dimension of array != 1"); + ereport(ERROR, + (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), + errmsg("array must be one-dimensional"))); while (num > 0) { if ( gist_qe(key, query) ) @@ -545,7 +549,8 @@ _ltree_consistent(PG_FUNCTION_ARGS) res = _arrq_cons(key, (ArrayType *) query); break; default: - elog(ERROR, "Unknown StrategyNumber: %d", strategy); + /* internal error */ + elog(ERROR, "unrecognized StrategyNumber: %d", strategy); } PG_RETURN_BOOL(res); } diff --git a/contrib/ltree/_ltree_op.c b/contrib/ltree/_ltree_op.c index f7cd8f2ab6..f55434d387 100644 --- a/contrib/ltree/_ltree_op.c +++ b/contrib/ltree/_ltree_op.c @@ -44,7 +44,9 @@ array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree ** found) ltree *item = (ltree *) ARR_DATA_PTR(la); if (ARR_NDIM(la) != 1) - elog(ERROR, "Dimension of array != 1"); + ereport(ERROR, + (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), + errmsg("array must be one-dimensional"))); if (found) *found = NULL; @@ -138,7 +140,9 @@ _lt_q_regex(PG_FUNCTION_ARGS) int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query)); if (ARR_NDIM(_query) != 1) - elog(ERROR, "Dimension of array != 1"); + ereport(ERROR, + (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), + errmsg("array must be one-dimensional"))); while (num > 0) { if ( array_iterator(_tree, ltq_regex, (void*)query, NULL) ) { diff --git a/contrib/ltree/expected/ltree.out b/contrib/ltree/expected/ltree.out index a87738bf35..dbd784b05c 100644 --- a/contrib/ltree/expected/ltree.out +++ b/contrib/ltree/expected/ltree.out @@ -1,12 +1,16 @@ \set ECHO none -psql:ltree.sql:7: NOTICE: ProcedureCreate: type ltree is not yet defined -psql:ltree.sql:12: NOTICE: Argument type "ltree" is only a shell -psql:ltree.sql:299: NOTICE: ProcedureCreate: type lquery is not yet defined -psql:ltree.sql:304: NOTICE: Argument type "lquery" is only a shell -psql:ltree.sql:410: NOTICE: ProcedureCreate: type ltxtquery is not yet defined -psql:ltree.sql:415: NOTICE: Argument type "ltxtquery" is only a shell -psql:ltree.sql:477: NOTICE: ProcedureCreate: type ltree_gist is not yet defined -psql:ltree.sql:482: NOTICE: Argument type "ltree_gist" is only a shell +psql:ltree.sql:7: NOTICE: type ltree is not yet defined +DETAIL: Creating a shell type definition. +psql:ltree.sql:12: NOTICE: argument type ltree is only a shell +psql:ltree.sql:299: NOTICE: type lquery is not yet defined +DETAIL: Creating a shell type definition. +psql:ltree.sql:304: NOTICE: argument type lquery is only a shell +psql:ltree.sql:410: NOTICE: type ltxtquery is not yet defined +DETAIL: Creating a shell type definition. +psql:ltree.sql:415: NOTICE: argument type ltxtquery is only a shell +psql:ltree.sql:477: NOTICE: type ltree_gist is not yet defined +DETAIL: Creating a shell type definition. +psql:ltree.sql:482: NOTICE: argument type ltree_gist is only a shell SELECT ''::ltree; ltree ------- diff --git a/contrib/ltree/lquery_op.c b/contrib/ltree/lquery_op.c index 1156723d58..72fd968d59 100644 --- a/contrib/ltree/lquery_op.c +++ b/contrib/ltree/lquery_op.c @@ -317,7 +317,9 @@ lt_q_regex(PG_FUNCTION_ARGS) int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query)); if (ARR_NDIM(_query) != 1) - elog(ERROR, "Dimension of array != 1"); + ereport(ERROR, + (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), + errmsg("array must be one-dimensional"))); while (num > 0) { if (DatumGetBool(DirectFunctionCall2(ltq_regex, diff --git a/contrib/ltree/ltree_gist.c b/contrib/ltree/ltree_gist.c index 41c92ac57b..65f408cd93 100644 --- a/contrib/ltree/ltree_gist.c +++ b/contrib/ltree/ltree_gist.c @@ -21,14 +21,18 @@ Datum ltree_gist_out(PG_FUNCTION_ARGS); Datum ltree_gist_in(PG_FUNCTION_ARGS) { - elog(ERROR, "Unimplemented"); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("ltree_gist_in() not implemented"))); PG_RETURN_DATUM(0); } Datum ltree_gist_out(PG_FUNCTION_ARGS) { - elog(ERROR, "Unimplemented"); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("ltree_gist_out() not implemented"))); PG_RETURN_DATUM(0); } @@ -604,7 +608,9 @@ arrq_cons(ltree_gist *key, ArrayType *_query) { int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query)); if (ARR_NDIM(_query) != 1) - elog(ERROR, "Dimension of array != 1"); + ereport(ERROR, + (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), + errmsg("array must be one-dimensional"))); while (num > 0) { if ( gist_qe(key, query) && gist_between(key, query) ) @@ -701,7 +707,8 @@ ltree_consistent(PG_FUNCTION_ARGS) res = arrq_cons(key, (ArrayType *) query); break; default: - elog(ERROR, "Unknown StrategyNumber: %d", strategy); + /* internal error */ + elog(ERROR, "unrecognized StrategyNumber: %d", strategy); } PG_RETURN_BOOL(res); } diff --git a/contrib/ltree/ltree_io.c b/contrib/ltree/ltree_io.c index 5e9dac48c0..24116b0242 100644 --- a/contrib/ltree/ltree_io.c +++ b/contrib/ltree/ltree_io.c @@ -20,7 +20,11 @@ PG_FUNCTION_INFO_V1(lquery_out); Datum lquery_out(PG_FUNCTION_ARGS); -#define UNCHAR elog(ERROR,"Syntax error in position %d near '%c'", (int)(ptr-buf), *ptr) +#define UNCHAR ereport(ERROR, \ + (errcode(ERRCODE_SYNTAX_ERROR), \ + errmsg("syntax error at position %d near \"%c\"", \ + (int)(ptr-buf), *ptr))); + typedef struct { @@ -73,8 +77,13 @@ ltree_in(PG_FUNCTION_ARGS) { lptr->len = ptr - lptr->start; if (lptr->len > 255) - elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d", - lptr->len, (int) (lptr->start - buf)); + ereport(ERROR, + (errcode(ERRCODE_NAME_TOO_LONG), + errmsg("name of level is too long"), + errdetail("name length is %d, must " \ + "be < 256, in position %d", + lptr->len, (int) (lptr->start - buf)))); + totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE); lptr++; state = LTPRS_WAITNAME; @@ -83,7 +92,8 @@ ltree_in(PG_FUNCTION_ARGS) UNCHAR; } else - elog(ERROR, "Inner error in parser"); + /* internal error */ + elog(ERROR, "internal error in parser"); ptr++; } @@ -91,13 +101,21 @@ ltree_in(PG_FUNCTION_ARGS) { lptr->len = ptr - lptr->start; if (lptr->len > 255) - elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d", - lptr->len, (int) (lptr->start - buf)); + ereport(ERROR, + (errcode(ERRCODE_NAME_TOO_LONG), + errmsg("name of level is too long"), + errdetail("name length is %d, must " \ + "be < 256, in position %d", + lptr->len, (int) (lptr->start - buf)))); + totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE); lptr++; } else if (!(state == LTPRS_WAITNAME && lptr == list)) - elog(ERROR, "Unexpected end of line"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("syntax error"), + errdetail("Unexpected end of line."))); result = (ltree *) palloc(LTREE_HDRSIZE + totallen); result->len = LTREE_HDRSIZE + totallen; @@ -261,8 +279,13 @@ lquery_in(PG_FUNCTION_ARGS) ((lptr->flag & LVAR_INCASE) ? 1 : 0) - ((lptr->flag & LVAR_ANYEND) ? 1 : 0); if (lptr->len > 255) - elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d", - lptr->len, (int) (lptr->start - buf)); + ereport(ERROR, + (errcode(ERRCODE_NAME_TOO_LONG), + errmsg("name of level is too long"), + errdetail("name length is %d, must " \ + "be < 256, in position %d", + lptr->len, (int) (lptr->start - buf)))); + state = LQPRS_WAITVAR; } else if (*ptr == '.') @@ -272,8 +295,13 @@ lquery_in(PG_FUNCTION_ARGS) ((lptr->flag & LVAR_INCASE) ? 1 : 0) - ((lptr->flag & LVAR_ANYEND) ? 1 : 0); if (lptr->len > 255) - elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d", - lptr->len, (int) (lptr->start - buf)); + ereport(ERROR, + (errcode(ERRCODE_NAME_TOO_LONG), + errmsg("name of level is too long"), + errdetail("name length is %d, must " \ + "be < 256, in position %d", + lptr->len, (int) (lptr->start - buf)))); + state = LQPRS_WAITLEVEL; curqlevel = NEXTLEV(curqlevel); } @@ -356,28 +384,44 @@ lquery_in(PG_FUNCTION_ARGS) UNCHAR; } else - elog(ERROR, "Inner error in parser"); + /* internal error */ + elog(ERROR, "internal error in parser"); ptr++; } if (state == LQPRS_WAITDELIM) { if (lptr->start == ptr) - elog(ERROR, "Unexpected end of line"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("syntax error"), + errdetail("Unexpected end of line."))); + lptr->len = ptr - lptr->start - ((lptr->flag & LVAR_SUBLEXEM) ? 1 : 0) - ((lptr->flag & LVAR_INCASE) ? 1 : 0) - ((lptr->flag & LVAR_ANYEND) ? 1 : 0); if (lptr->len == 0) - elog(ERROR, "Unexpected end of line"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("syntax error"), + errdetail("Unexpected end of line."))); + if (lptr->len > 255) - elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d", - lptr->len, (int) (lptr->start - buf)); + ereport(ERROR, + (errcode(ERRCODE_NAME_TOO_LONG), + errmsg("name of level is too long"), + errdetail("name length is %d, must " \ + "be < 256, in position %d", + lptr->len, (int) (lptr->start - buf)))); } else if (state == LQPRS_WAITOPEN) curqlevel->high = 0xffff; else if (state != LQPRS_WAITEND) - elog(ERROR, "Unexpected end of line"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("syntax error"), + errdetail("Unexpected end of line."))); curqlevel = tmpql; totallen = LQUERY_HDRSIZE; @@ -394,7 +438,12 @@ lquery_in(PG_FUNCTION_ARGS) } } else if (curqlevel->low > curqlevel->high) - elog(ERROR, "Low limit(%d) is greater than upper(%d)", curqlevel->low, curqlevel->high); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("syntax error"), + errdetail("Low limit(%d) is greater than upper(%d).", + curqlevel->low, curqlevel->high))); + curqlevel = NEXTLEV(curqlevel); } diff --git a/contrib/ltree/ltree_op.c b/contrib/ltree/ltree_op.c index 44721bf6d0..1b3c80b726 100644 --- a/contrib/ltree/ltree_op.c +++ b/contrib/ltree/ltree_op.c @@ -197,7 +197,9 @@ inner_subltree(ltree * t, int4 startpos, int4 endpos) int i; if (startpos < 0 || endpos < 0 || startpos >= t->numlevel || startpos > endpos) - elog(ERROR, "Wrong positions"); + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("invalid positions"))); if (endpos > t->numlevel) endpos = t->numlevel; diff --git a/contrib/ltree/ltxtquery_io.c b/contrib/ltree/ltxtquery_io.c index c07abaa228..f63c9ee6fb 100644 --- a/contrib/ltree/ltxtquery_io.c +++ b/contrib/ltree/ltxtquery_io.c @@ -81,13 +81,17 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, uint1 *flag = 0; } else if (!isspace((unsigned int) *(state->buf))) - elog(ERROR, "Operand syntax error"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("operand syntax error"))); break; case INOPERAND: if (ISALNUM(*(state->buf))) { if (*flag) - elog(ERROR, "Modificators syntax error"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("modificators syntax error"))); (*lenval)++; } else if (*(state->buf) == '%') @@ -142,9 +146,13 @@ pushquery(QPRS_STATE * state, int4 type, int4 val, int4 distance, int4 lenval, u tmp->val = val; tmp->flag = flag; if (distance > 0xffff) - elog(ERROR, "Value is too big"); + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("value is too big"))); if (lenval > 0xff) - elog(ERROR, "Operand is too long"); + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("operand is too long"))); tmp->distance = distance; tmp->length = lenval; tmp->next = state->str; @@ -159,7 +167,9 @@ static void pushval_asis(QPRS_STATE * state, int type, char *strval, int lenval, uint16 flag) { if (lenval > 0xffff) - elog(ERROR, "Word is too long"); + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("word is too long"))); pushquery(state, type, ltree_crc32_sz((uint8 *) strval, lenval), state->curop - state->op, lenval, flag); @@ -214,7 +224,8 @@ makepol(QPRS_STATE * state) else { if (lenstack == STACKDEPTH) - elog(ERROR, "Stack too short"); + /* internal error */ + elog(ERROR, "stack too short"); stack[lenstack] = val; lenstack++; } @@ -239,7 +250,10 @@ makepol(QPRS_STATE * state) break; case ERR: default: - elog(ERROR, "Syntax error"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("syntax error"))); + return ERR; } @@ -314,7 +328,11 @@ queryin(char *buf) /* parse query & make polish notation (postfix, but in reverse order) */ makepol(&state); if (!state.num) - elog(ERROR, "Empty query"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("syntax error"), + errdetail("Empty query."))); + /* make finish struct */ commonlen = COMPUTESIZE(state.num, state.sumlen); query = (ltxtquery *) palloc(commonlen); @@ -483,7 +501,11 @@ ltxtq_out(PG_FUNCTION_ARGS) INFIX nrm; if (query->size == 0) - elog(ERROR, "Empty"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("syntax error"), + errdetail("Empty query."))); + nrm.curpol = GETQUERY(query); nrm.buflen = 32; nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen); |
