Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbb0e301

Browse files
committed
Make a cleanup pass over error reports in tsearch code. Use ereport
for user-facing errors, fix some poor choices of errcode, adhere tomessage style guide.
1 parent664782e commitbb0e301

File tree

9 files changed

+71
-47
lines changed

9 files changed

+71
-47
lines changed

‎src/backend/commands/tsearchcmds.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/tsearchcmds.c,v 1.7 2007/11/15 22:25:15 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/tsearchcmds.c,v 1.8 2007/11/28 21:56:30 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -95,7 +95,8 @@ get_ts_parser_func(DefElem *defel, int attnum)
9595
break;
9696
default:
9797
/* should not be here */
98-
elog(ERROR,"unknown attribute for text search parser: %d",attnum);
98+
elog(ERROR,"unrecognized attribute for text search parser: %d",
99+
attnum);
99100
nargs=0;/* keep compiler quiet */
100101
}
101102

@@ -895,7 +896,7 @@ get_ts_template_func(DefElem *defel, int attnum)
895896
break;
896897
default:
897898
/* should not be here */
898-
elog(ERROR,"unknown attribute for text search template: %d",
899+
elog(ERROR,"unrecognized attribute for text search template: %d",
899900
attnum);
900901
nargs=0;/* keep compiler quiet */
901902
}

‎src/backend/tsearch/dict_thesaurus.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/tsearch/dict_thesaurus.c,v 1.9 2007/11/2804:24:38 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/tsearch/dict_thesaurus.c,v 1.10 2007/11/2821:56:30 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -423,11 +423,18 @@ compileTheLexeme(DictThesaurus *d)
423423
PointerGetDatum(NULL)));
424424

425425
if (!ptr)
426-
elog(ERROR,"thesaurus word-sample \"%s\" isn't recognized by subdictionary (rule %d)",
427-
d->wrds[i].lexeme,d->wrds[i].entries->idsubst+1);
426+
ereport(ERROR,
427+
(errcode(ERRCODE_CONFIG_FILE_ERROR),
428+
errmsg("thesaurus sample word \"%s\" isn't recognized by subdictionary (rule %d)",
429+
d->wrds[i].lexeme,
430+
d->wrds[i].entries->idsubst+1)));
428431
elseif (!(ptr->lexeme))
429-
elog(ERROR,"thesaurus word-sample \"%s\" is recognized as stop-word, use \"?\" for stop words instead (rule %d)",
430-
d->wrds[i].lexeme,d->wrds[i].entries->idsubst+1);
432+
ereport(ERROR,
433+
(errcode(ERRCODE_CONFIG_FILE_ERROR),
434+
errmsg("thesaurus sample word \"%s\" is a stop word (rule %d)",
435+
d->wrds[i].lexeme,
436+
d->wrds[i].entries->idsubst+1),
437+
errhint("Use \"?\" to represent a stop word within a sample phrase.")));
431438
else
432439
{
433440
while (ptr->lexeme)
@@ -570,11 +577,17 @@ compileTheSubstitute(DictThesaurus *d)
570577
}
571578
elseif (lexized)
572579
{
573-
elog(ERROR,"thesaurus word \"%s\" in substitution is a stop-word (rule %d)",inptr->lexeme,i+1);
580+
ereport(ERROR,
581+
(errcode(ERRCODE_CONFIG_FILE_ERROR),
582+
errmsg("thesaurus substitute word \"%s\" is a stop word (rule %d)",
583+
inptr->lexeme,i+1)));
574584
}
575585
else
576586
{
577-
elog(ERROR,"thesaurus word \"%s\" in substitution isn't recognized (rule %d)",inptr->lexeme,i+1);
587+
ereport(ERROR,
588+
(errcode(ERRCODE_CONFIG_FILE_ERROR),
589+
errmsg("thesaurus substitute word \"%s\" isn't recognized by subdictionary (rule %d)",
590+
inptr->lexeme,i+1)));
578591
}
579592

580593
if (inptr->lexeme)
@@ -583,7 +596,10 @@ compileTheSubstitute(DictThesaurus *d)
583596
}
584597

585598
if (outptr==d->subst[i].res)
586-
elog(ERROR,"all words in thesaurus substitution are stop words (rule %d)",i+1);
599+
ereport(ERROR,
600+
(errcode(ERRCODE_CONFIG_FILE_ERROR),
601+
errmsg("thesaurus substitute phrase is empty (rule %d)",
602+
i+1)));
587603

588604
d->subst[i].reslen=outptr-d->subst[i].res;
589605

@@ -794,7 +810,7 @@ thesaurus_lexize(PG_FUNCTION_ARGS)
794810
uint16curpos=0;
795811
boolmoreres= false;
796812

797-
if (PG_NARGS()<4||dstate==NULL)
813+
if (PG_NARGS()!=4||dstate==NULL)
798814
elog(ERROR,"forbidden call of thesaurus or nested call");
799815

800816
if (dstate->isend)

‎src/backend/tsearch/spell.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/tsearch/spell.c,v 1.7 2007/11/15 22:25:16 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/tsearch/spell.c,v 1.8 2007/11/28 21:56:30 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -501,7 +501,7 @@ parse_affentry(char *str, char *mask, char *find, char *repl,
501501
lineno,filename)));
502502
}
503503
else
504-
elog(ERROR,"unknown state in parse_affentry: %d",state);
504+
elog(ERROR,"unrecognized state in parse_affentry: %d",state);
505505

506506
str+=pg_mblen(str);
507507
}

‎src/backend/tsearch/ts_parse.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/tsearch/ts_parse.c,v 1.5 2007/11/15 22:25:16 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/tsearch/ts_parse.c,v 1.6 2007/11/28 21:56:30 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -380,15 +380,17 @@ parsetext(Oid cfgId, ParsedText *prs, char *buf, int buflen)
380380
{
381381
#ifdefIGNORE_LONGLEXEME
382382
ereport(NOTICE,
383-
(errcode(ERRCODE_SYNTAX_ERROR),
383+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
384384
errmsg("word is too long to be indexed"),
385385
errdetail("Words longer than %d characters are ignored.",
386386
MAXSTRLEN)));
387387
continue;
388388
#else
389389
ereport(ERROR,
390-
(errcode(ERRCODE_SYNTAX_ERROR),
391-
errmsg("word is too long to be indexed")));
390+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
391+
errmsg("word is too long to be indexed"),
392+
errdetail("Words longer than %d characters are ignored.",
393+
MAXSTRLEN)));
392394
#endif
393395
}
394396

@@ -547,15 +549,17 @@ hlparsetext(Oid cfgId, HeadlineParsedText *prs, TSQuery query, char *buf, int bu
547549
{
548550
#ifdefIGNORE_LONGLEXEME
549551
ereport(NOTICE,
550-
(errcode(ERRCODE_SYNTAX_ERROR),
552+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
551553
errmsg("word is too long to be indexed"),
552554
errdetail("Words longer than %d characters are ignored.",
553555
MAXSTRLEN)));
554556
continue;
555557
#else
556558
ereport(ERROR,
557-
(errcode(ERRCODE_SYNTAX_ERROR),
558-
errmsg("word is too long to be indexed")));
559+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
560+
errmsg("word is too long to be indexed"),
561+
errdetail("Words longer than %d characters are ignored.",
562+
MAXSTRLEN)));
559563
#endif
560564
}
561565

‎src/backend/utils/adt/tsquery.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.11 2007/11/16 15:05:59 teodor Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.12 2007/11/28 21:56:30 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -237,12 +237,12 @@ pushValue_internal(TSQueryParserState state, pg_crc32 valcrc, int distance, int
237237

238238
if (distance >=MAXSTRPOS)
239239
ereport(ERROR,
240-
(errcode(ERRCODE_SYNTAX_ERROR),
240+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
241241
errmsg("value is too big in tsquery: \"%s\"",
242242
state->buffer)));
243243
if (lenval >=MAXSTRLEN)
244244
ereport(ERROR,
245-
(errcode(ERRCODE_SYNTAX_ERROR),
245+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
246246
errmsg("operand is too long in tsquery: \"%s\"",
247247
state->buffer)));
248248

@@ -269,7 +269,7 @@ pushValue(TSQueryParserState state, char *strval, int lenval, int2 weight)
269269

270270
if (lenval >=MAXSTRLEN)
271271
ereport(ERROR,
272-
(errcode(ERRCODE_SYNTAX_ERROR),
272+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
273273
errmsg("word is too long in tsquery: \"%s\"",
274274
state->buffer)));
275275

@@ -396,7 +396,7 @@ findoprnd_recurse(QueryItem *ptr, uint32 *pos, int nnodes)
396396
check_stack_depth();
397397

398398
if (*pos >=nnodes)
399-
elog(ERROR,"malformed tsquery; operand not found");
399+
elog(ERROR,"malformed tsquery: operand not found");
400400

401401
if (ptr[*pos].type==QI_VAL||
402402
ptr[*pos].type==QI_VALSTOP)/* need to handle VALSTOP here, they
@@ -443,7 +443,7 @@ findoprnd(QueryItem *ptr, int size)
443443
findoprnd_recurse(ptr,&pos,size);
444444

445445
if (pos!=size)
446-
elog(ERROR,"malformed tsquery; extra nodes");
446+
elog(ERROR,"malformed tsquery: extra nodes");
447447
}
448448

449449

@@ -531,7 +531,7 @@ parse_tsquery(char *buf,
531531
memcpy(&ptr[i],item,sizeof(QueryOperator));
532532
break;
533533
default:
534-
elog(ERROR,"unknown QueryItem type %d",item->type);
534+
elog(ERROR,"unrecognized QueryItem type: %d",item->type);
535535
}
536536
i++;
537537
}
@@ -718,7 +718,7 @@ infix(INFIX *in, bool first)
718718
break;
719719
default:
720720
/* OP_NOT is handled in above if-branch */
721-
elog(ERROR,"unexpected operator type %d",op);
721+
elog(ERROR,"unrecognized operator type: %d",op);
722722
}
723723
in->cur=strchr(in->cur,'\0');
724724
pfree(nrm.buf);
@@ -798,7 +798,7 @@ tsquerysend(PG_FUNCTION_ARGS)
798798
pq_sendint(&buf,item->operator.oper,sizeof(item->operator.oper));
799799
break;
800800
default:
801-
elog(ERROR,"unknown tsquery node type %d",item->type);
801+
elog(ERROR,"unrecognized tsquery node type: %d",item->type);
802802
}
803803
item++;
804804
}
@@ -853,13 +853,13 @@ tsqueryrecv(PG_FUNCTION_ARGS)
853853
/* Sanity checks */
854854

855855
if (weight>0xF)
856-
elog(ERROR,"invalid tsquery; invalid weight bitmap");
856+
elog(ERROR,"invalid tsquery: invalid weight bitmap");
857857

858858
if (val_len>MAXSTRLEN)
859-
elog(ERROR,"invalid tsquery; operand too long");
859+
elog(ERROR,"invalid tsquery: operand too long");
860860

861861
if (datalen>MAXSTRPOS)
862-
elog(ERROR,"invalid tsquery; total operand length exceeded");
862+
elog(ERROR,"invalid tsquery: total operand length exceeded");
863863

864864
/* Looks valid. */
865865

@@ -886,14 +886,15 @@ tsqueryrecv(PG_FUNCTION_ARGS)
886886

887887
oper= (int8)pq_getmsgint(buf,sizeof(int8));
888888
if (oper!=OP_NOT&&oper!=OP_OR&&oper!=OP_AND)
889-
elog(ERROR,"invalid tsquery; unknown operator type %d", (int)oper);
889+
elog(ERROR,"invalid tsquery: unrecognized operator type %d",
890+
(int)oper);
890891
if (i==size-1)
891892
elog(ERROR,"invalid pointer to right operand");
892893

893894
item->operator.oper=oper;
894895
}
895896
else
896-
elog(ERROR,"unknown tsquery node type %d",item->type);
897+
elog(ERROR,"unrecognized tsquery node type: %d",item->type);
897898

898899
item++;
899900
}

‎src/backend/utils/adt/tsquery_cleanup.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_cleanup.c,v 1.7 2007/11/15 22:25:16 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_cleanup.c,v 1.8 2007/11/28 21:56:30 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -281,7 +281,8 @@ clean_fakeval(QueryItem *ptr, int *len)
281281
resroot=clean_fakeval_intree(root,&result);
282282
if (result!=V_UNKNOWN)
283283
{
284-
elog(NOTICE,"query contains only stopword(s) or doesn't contain lexeme(s), ignored");
284+
ereport(NOTICE,
285+
(errmsg("query contains only stopword(s) or doesn't contain lexeme(s), ignored")));
285286
*len=0;
286287
returnNULL;
287288
}

‎src/backend/utils/adt/tsvector.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector.c,v 1.9 2007/11/16 15:05:59 teodor Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector.c,v 1.10 2007/11/28 21:56:30 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -480,13 +480,13 @@ tsvectorrecv(PG_FUNCTION_ARGS)
480480

481481
lex_len=strlen(lexeme);
482482
if (lex_len<0||lex_len>MAXSTRLEN)
483-
elog(ERROR,"invalid tsvector; lexeme too long");
483+
elog(ERROR,"invalid tsvector: lexeme too long");
484484

485485
if (datalen>MAXSTRPOS)
486-
elog(ERROR,"invalid tsvector; maximum total lexeme length exceeded");
486+
elog(ERROR,"invalid tsvector: maximum total lexeme length exceeded");
487487

488488
if (npos>MAXNUMPOS)
489-
elog(ERROR,"unexpected number of positions");
489+
elog(ERROR,"unexpected number oftsvectorpositions");
490490

491491
/*
492492
* Looks valid. Fill the WordEntry struct, and copy lexeme.

‎src/backend/utils/adt/tsvector_op.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.9 2007/11/16 01:51:22 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.10 2007/11/28 21:56:30 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -226,9 +226,9 @@ tsvector_setweight(PG_FUNCTION_ARGS)
226226
case'd':
227227
w=0;
228228
break;
229-
/* internal error */
230229
default:
231-
elog(ERROR,"unrecognized weight");
230+
/* internal error */
231+
elog(ERROR,"unrecognized weight: %d",cw);
232232
}
233233

234234
out= (TSVector)palloc(VARSIZE(in));
@@ -609,7 +609,7 @@ TS_execute(QueryItem *curitem, void *checkval, bool calcnot,
609609
returnTS_execute(curitem+1,checkval,calcnot,chkcond);
610610

611611
default:
612-
elog(ERROR,"unknown operator %d",curitem->operator.oper);
612+
elog(ERROR,"unrecognized operator: %d",curitem->operator.oper);
613613
}
614614

615615
/* not reachable, but keep compiler quiet */

‎src/backend/utils/adt/tsvector_parser.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_parser.c,v 1.4 2007/11/15 22:25:16 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_parser.c,v 1.5 2007/11/28 21:56:30 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -359,7 +359,8 @@ gettoken_tsvector(TSVectorParseState state,
359359
PRSSYNTAXERROR;
360360
}
361361
else/* internal error */
362-
elog(ERROR,"internal error in gettoken_tsvector");
362+
elog(ERROR,"unrecognized state in gettoken_tsvector: %d",
363+
statecode);
363364

364365
/* get next char */
365366
state->prsbuf+=pg_mblen(state->prsbuf);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp