1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-11 10:01:57 +03:00

Error message editing in backend/utils (except /adt).

This commit is contained in:
Tom Lane
2003-07-25 20:18:01 +00:00
parent 9fecf302f7
commit 689eb53e47
29 changed files with 739 additions and 521 deletions

View File

@ -56,7 +56,7 @@
* Since all the bookkeeping and buffer memory is allocated with palloc(),
* and the underlying file(s) are made with OpenTemporaryFile, all resources
* for a logical tape set are certain to be cleaned up even if processing
* is aborted by elog(ERROR). To avoid confusion, the caller should take
* is aborted by ereport(ERROR). To avoid confusion, the caller should take
* care that all calls for a single LogicalTapeSet are made in the same
* palloc context.
*
@ -64,7 +64,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/sort/logtape.c,v 1.9 2003/03/27 16:51:29 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/sort/logtape.c,v 1.10 2003/07/25 20:17:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -189,21 +189,25 @@ static void ltsDumpBuffer(LogicalTapeSet *lts, LogicalTape *lt);
* "holes" in file), since BufFile doesn't allow that. The first write pass
* must write blocks sequentially.
*
* No need for an error return convention; we elog() on any error.
* No need for an error return convention; we ereport() on any error.
*/
static void
ltsWriteBlock(LogicalTapeSet *lts, long blocknum, void *buffer)
{
if (BufFileSeekBlock(lts->pfile, blocknum) != 0 ||
BufFileWrite(lts->pfile, buffer, BLCKSZ) != BLCKSZ)
elog(ERROR, "ltsWriteBlock: failed to write block %ld of temporary file\n\t\tPerhaps out of disk space?",
blocknum);
ereport(ERROR,
/* XXX is it okay to assume errno is correct? */
(errcode_for_file_access(),
errmsg("could not write block %ld of temporary file: %m",
blocknum),
errhint("Perhaps out of disk space?")));
}
/*
* Read a block-sized buffer from the specified block of the underlying file.
*
* No need for an error return convention; we elog() on any error. This
* No need for an error return convention; we ereport() on any error. This
* module should never attempt to read a block it doesn't know is there.
*/
static void
@ -211,8 +215,11 @@ ltsReadBlock(LogicalTapeSet *lts, long blocknum, void *buffer)
{
if (BufFileSeekBlock(lts->pfile, blocknum) != 0 ||
BufFileRead(lts->pfile, buffer, BLCKSZ) != BLCKSZ)
elog(ERROR, "ltsReadBlock: failed to read block %ld of temporary file",
blocknum);
ereport(ERROR,
/* XXX is it okay to assume errno is correct? */
(errcode_for_file_access(),
errmsg("could not read block %ld of temporary file: %m",
blocknum)));
}
/*
@ -543,7 +550,7 @@ ltsDumpBuffer(LogicalTapeSet *lts, LogicalTape *lt)
/*
* Write to a logical tape.
*
* There are no error returns; we elog() on failure.
* There are no error returns; we ereport() on failure.
*/
void
LogicalTapeWrite(LogicalTapeSet *lts, int tapenum,
@ -566,7 +573,7 @@ LogicalTapeWrite(LogicalTapeSet *lts, int tapenum,
else
{
/* Hmm, went directly from reading to writing? */
elog(ERROR, "LogicalTapeWrite: impossible state");
elog(ERROR, "invalid logtape state: should be dirty");
}
lt->numFullBlocks++;
lt->curBlockNumber++;
@ -828,7 +835,7 @@ LogicalTapeBackspace(LogicalTapeSet *lts, int tapenum, size_t size)
long datablocknum = ltsRecallPrevBlockNum(lts, lt->indirect);
if (datablocknum == -1L)
elog(ERROR, "LogicalTapeBackspace: unexpected end of tape");
elog(ERROR, "unexpected end of tape");
lt->curBlockNumber--;
if (nblocks == 0)
{
@ -885,7 +892,7 @@ LogicalTapeSeek(LogicalTapeSet *lts, int tapenum,
long datablocknum = ltsRecallPrevBlockNum(lts, lt->indirect);
if (datablocknum == -1L)
elog(ERROR, "LogicalTapeSeek: unexpected end of tape");
elog(ERROR, "unexpected end of tape");
if (--lt->curBlockNumber == blocknum)
ltsReadBlock(lts, datablocknum, (void *) lt->buffer);
}
@ -895,7 +902,7 @@ LogicalTapeSeek(LogicalTapeSet *lts, int tapenum,
lt->frozen);
if (datablocknum == -1L)
elog(ERROR, "LogicalTapeSeek: unexpected end of tape");
elog(ERROR, "unexpected end of tape");
if (++lt->curBlockNumber == blocknum)
ltsReadBlock(lts, datablocknum, (void *) lt->buffer);
}

View File

@ -78,7 +78,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplesort.c,v 1.33 2003/05/13 04:38:58 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplesort.c,v 1.34 2003/07/25 20:17:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -319,7 +319,7 @@ struct Tuplesortstate
* stored in the Tuplesortstate record, if needed. They are also expected
* to adjust state->availMem by the amount of memory space (not tape space!)
* released or consumed. There is no error return from either writetup
* or readtup; they should elog() on failure.
* or readtup; they should ereport() on failure.
*
*
* NOTES about memory consumption calculations:
@ -691,7 +691,7 @@ puttuple_common(Tuplesortstate *state, void *tuple)
dumptuples(state, false);
break;
default:
elog(ERROR, "tuplesort_puttuple: invalid state");
elog(ERROR, "invalid tuplesort state");
break;
}
}
@ -738,7 +738,7 @@ tuplesort_performsort(Tuplesortstate *state)
state->markpos_eof = false;
break;
default:
elog(ERROR, "tuplesort_performsort: invalid state");
elog(ERROR, "invalid tuplesort state");
break;
}
}
@ -856,7 +856,7 @@ tuplesort_gettuple(Tuplesortstate *state, bool forward,
if (!LogicalTapeBackspace(state->tapeset,
state->result_tape,
tuplen + sizeof(unsigned int)))
elog(ERROR, "tuplesort_gettuple: bogus tuple len in backward scan");
elog(ERROR, "bogus tuple length in backward scan");
return NULL;
}
}
@ -871,7 +871,7 @@ tuplesort_gettuple(Tuplesortstate *state, bool forward,
if (!LogicalTapeBackspace(state->tapeset,
state->result_tape,
tuplen))
elog(ERROR, "tuplesort_gettuple: bogus tuple len in backward scan");
elog(ERROR, "bogus tuple length in backward scan");
tup = READTUP(state, state->result_tape, tuplen);
return tup;
@ -923,7 +923,7 @@ tuplesort_gettuple(Tuplesortstate *state, bool forward,
return NULL;
default:
elog(ERROR, "tuplesort_gettuple: invalid state");
elog(ERROR, "invalid tuplesort state");
return NULL; /* keep compiler quiet */
}
}
@ -1483,7 +1483,7 @@ tuplesort_rescan(Tuplesortstate *state)
state->markpos_eof = false;
break;
default:
elog(ERROR, "tuplesort_rescan: invalid state");
elog(ERROR, "invalid tuplesort state");
break;
}
}
@ -1510,7 +1510,7 @@ tuplesort_markpos(Tuplesortstate *state)
state->markpos_eof = state->eof_reached;
break;
default:
elog(ERROR, "tuplesort_markpos: invalid state");
elog(ERROR, "invalid tuplesort state");
break;
}
}
@ -1539,7 +1539,7 @@ tuplesort_restorepos(Tuplesortstate *state)
state->eof_reached = state->markpos_eof;
break;
default:
elog(ERROR, "tuplesort_restorepos: invalid state");
elog(ERROR, "invalid tuplesort state");
break;
}
}
@ -1662,9 +1662,9 @@ getlen(Tuplesortstate *state, int tapenum, bool eofOK)
if (LogicalTapeRead(state->tapeset, tapenum, (void *) &len,
sizeof(len)) != sizeof(len))
elog(ERROR, "tuplesort: unexpected end of tape");
elog(ERROR, "unexpected end of tape");
if (len == 0 && !eofOK)
elog(ERROR, "tuplesort: unexpected end of data");
elog(ERROR, "unexpected end of data");
return len;
}
@ -1779,8 +1779,7 @@ SelectSortFunction(Oid sortOperator,
ObjectIdGetDatum(sortOperator),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "SelectSortFunction: cache lookup failed for operator %u",
sortOperator);
elog(ERROR, "cache lookup failed for operator %u", sortOperator);
optup = (Form_pg_operator) GETSTRUCT(tuple);
if (strcmp(NameStr(optup->oprname), ">") == 0)
*kind = SORTFUNC_REVLT;
@ -1817,8 +1816,7 @@ myFunctionCall2(FmgrInfo *flinfo, Datum arg1, Datum arg2)
/* Check for null result, since caller is clearly not expecting one */
if (fcinfo.isnull)
elog(ERROR, "FunctionCall2: function %u returned NULL",
fcinfo.flinfo->fn_oid);
elog(ERROR, "function %u returned NULL", fcinfo.flinfo->fn_oid);
return result;
}
@ -1891,7 +1889,7 @@ inlineApplySortFunction(FmgrInfo *sortFunction, SortFunctionKind kind,
datum1, datum2));
default:
elog(ERROR, "Invalid SortFunctionKind %d", (int) kind);
elog(ERROR, "unrecognized SortFunctionKind: %d", (int) kind);
return 0; /* can't get here, but keep compiler quiet */
}
}
@ -2000,11 +1998,11 @@ readtup_heap(Tuplesortstate *state, int tapenum, unsigned int len)
/* read in the tuple proper */
if (LogicalTapeRead(state->tapeset, tapenum, (void *) tuple->t_data,
tuple->t_len) != tuple->t_len)
elog(ERROR, "tuplesort: unexpected end of data");
elog(ERROR, "unexpected end of data");
if (state->randomAccess) /* need trailing length word? */
if (LogicalTapeRead(state->tapeset, tapenum, (void *) &tuplen,
sizeof(tuplen)) != sizeof(tuplen))
elog(ERROR, "tuplesort: unexpected end of data");
elog(ERROR, "unexpected end of data");
return (void *) tuple;
}
@ -2079,7 +2077,10 @@ comparetup_index(Tuplesortstate *state, const void *a, const void *b)
* a bogus error in that case.
*/
if (state->enforceUnique && !equal_hasnull && tuple1 != tuple2)
elog(ERROR, "Cannot create unique index. Table contains non-unique values");
ereport(ERROR,
(errcode(ERRCODE_UNIQUE_VIOLATION),
errmsg("could not create unique index"),
errdetail("Table contains duplicated values.")));
return 0;
}
@ -2127,11 +2128,11 @@ readtup_index(Tuplesortstate *state, int tapenum, unsigned int len)
USEMEM(state, GetMemoryChunkSpace(tuple));
if (LogicalTapeRead(state->tapeset, tapenum, (void *) tuple,
tuplen) != tuplen)
elog(ERROR, "tuplesort: unexpected end of data");
elog(ERROR, "unexpected end of data");
if (state->randomAccess) /* need trailing length word? */
if (LogicalTapeRead(state->tapeset, tapenum, (void *) &tuplen,
sizeof(tuplen)) != sizeof(tuplen))
elog(ERROR, "tuplesort: unexpected end of data");
elog(ERROR, "unexpected end of data");
return (void *) tuple;
}
@ -2199,11 +2200,11 @@ readtup_datum(Tuplesortstate *state, int tapenum, unsigned int len)
USEMEM(state, GetMemoryChunkSpace(tuple));
if (LogicalTapeRead(state->tapeset, tapenum, (void *) tuple,
tuplen) != tuplen)
elog(ERROR, "tuplesort: unexpected end of data");
elog(ERROR, "unexpected end of data");
if (state->randomAccess) /* need trailing length word? */
if (LogicalTapeRead(state->tapeset, tapenum, (void *) &tuplen,
sizeof(tuplen)) != sizeof(tuplen))
elog(ERROR, "tuplesort: unexpected end of data");
elog(ERROR, "unexpected end of data");
if (!tuple->isNull && !state->datumTypeByVal)
tuple->val = PointerGetDatum(((char *) tuple) +

View File

@ -36,7 +36,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplestore.c,v 1.13 2003/04/29 03:21:29 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplestore.c,v 1.14 2003/07/25 20:18:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -171,7 +171,7 @@ struct Tuplestorestate
* stored in the Tuplestorestate record, if needed. They are also expected
* to adjust state->availMem by the amount of memory space (not tape space!)
* released or consumed. There is no error return from either writetup
* or readtup; they should elog() on failure.
* or readtup; they should ereport() on failure.
*
*
* NOTES about memory consumption calculations:
@ -361,12 +361,12 @@ tuplestore_puttuple(Tuplestorestate *state, void *tuple)
if (BufFileSeek(state->myfile,
state->writepos_file, state->writepos_offset,
SEEK_SET) != 0)
elog(ERROR, "tuplestore_puttuple: seek(EOF) failed");
elog(ERROR, "seek to EOF failed");
state->status = TSS_WRITEFILE;
WRITETUP(state, tuple);
break;
default:
elog(ERROR, "tuplestore_puttuple: invalid state");
elog(ERROR, "invalid tuplestore state");
break;
}
}
@ -430,7 +430,7 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward,
if (BufFileSeek(state->myfile,
state->readpos_file, state->readpos_offset,
SEEK_SET) != 0)
elog(ERROR, "tuplestore_gettuple: seek() failed");
elog(ERROR, "seek failed");
state->status = TSS_READFILE;
/* FALL THRU into READFILE case */
@ -488,7 +488,7 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward,
if (BufFileSeek(state->myfile, 0,
-(long) (tuplen + sizeof(unsigned int)),
SEEK_CUR) != 0)
elog(ERROR, "tuplestore_gettuple: bogus tuple len in backward scan");
elog(ERROR, "bogus tuple length in backward scan");
return NULL;
}
tuplen = getlen(state, false);
@ -502,12 +502,12 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward,
if (BufFileSeek(state->myfile, 0,
-(long) tuplen,
SEEK_CUR) != 0)
elog(ERROR, "tuplestore_gettuple: bogus tuple len in backward scan");
elog(ERROR, "bogus tuple length in backward scan");
tup = READTUP(state, tuplen);
return tup;
default:
elog(ERROR, "tuplestore_gettuple: invalid state");
elog(ERROR, "invalid tuplestore state");
return NULL; /* keep compiler quiet */
}
}
@ -559,10 +559,10 @@ tuplestore_rescan(Tuplestorestate *state)
case TSS_READFILE:
state->eof_reached = false;
if (BufFileSeek(state->myfile, 0, 0L, SEEK_SET) != 0)
elog(ERROR, "tuplestore_rescan: seek(0) failed");
elog(ERROR, "seek to start failed");
break;
default:
elog(ERROR, "tuplestore_rescan: invalid state");
elog(ERROR, "invalid tuplestore state");
break;
}
}
@ -598,7 +598,7 @@ tuplestore_markpos(Tuplestorestate *state)
&state->markpos_offset);
break;
default:
elog(ERROR, "tuplestore_markpos: invalid state");
elog(ERROR, "invalid tuplestore state");
break;
}
}
@ -630,7 +630,7 @@ tuplestore_restorepos(Tuplestorestate *state)
elog(ERROR, "tuplestore_restorepos failed");
break;
default:
elog(ERROR, "tuplestore_restorepos: invalid state");
elog(ERROR, "invalid tuplestore state");
break;
}
}
@ -650,9 +650,9 @@ getlen(Tuplestorestate *state, bool eofOK)
if (nbytes == sizeof(len))
return len;
if (nbytes != 0)
elog(ERROR, "tuplestore: unexpected end of tape");
elog(ERROR, "unexpected end of tape");
if (!eofOK)
elog(ERROR, "tuplestore: unexpected end of data");
elog(ERROR, "unexpected end of data");
return 0;
}
@ -684,14 +684,14 @@ writetup_heap(Tuplestorestate *state, void *tup)
tuplen = tuple->t_len + sizeof(tuplen);
if (BufFileWrite(state->myfile, (void *) &tuplen,
sizeof(tuplen)) != sizeof(tuplen))
elog(ERROR, "tuplestore: write failed");
elog(ERROR, "write failed");
if (BufFileWrite(state->myfile, (void *) tuple->t_data,
tuple->t_len) != (size_t) tuple->t_len)
elog(ERROR, "tuplestore: write failed");
elog(ERROR, "write failed");
if (state->randomAccess) /* need trailing length word? */
if (BufFileWrite(state->myfile, (void *) &tuplen,
sizeof(tuplen)) != sizeof(tuplen))
elog(ERROR, "tuplestore: write failed");
elog(ERROR, "write failed");
FREEMEM(state, GetMemoryChunkSpace(tuple));
heap_freetuple(tuple);
@ -712,10 +712,10 @@ readtup_heap(Tuplestorestate *state, unsigned int len)
/* read in the tuple proper */
if (BufFileRead(state->myfile, (void *) tuple->t_data,
tuple->t_len) != (size_t) tuple->t_len)
elog(ERROR, "tuplestore: unexpected end of data");
elog(ERROR, "unexpected end of data");
if (state->randomAccess) /* need trailing length word? */
if (BufFileRead(state->myfile, (void *) &tuplen,
sizeof(tuplen)) != sizeof(tuplen))
elog(ERROR, "tuplestore: unexpected end of data");
elog(ERROR, "unexpected end of data");
return (void *) tuple;
}