mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
Fix a number of places that produced XX000 errors in the regression tests.
It's against project policy to use elog() for user-facing errors, or to omit an errcode() selection for errors that aren't supposed to be "can't happen" cases. Fix all the violations of this policy that result in ERRCODE_INTERNAL_ERROR log entries during the standard regression tests, as errors that can reliably be triggered from SQL surely should be considered user-facing. I also looked through all the files touched by this commit and fixed other nearby problems of the same ilk. I do not claim to have fixed all violations of the policy, just the ones in these files. In a few places I also changed existing ERRCODE choices that didn't seem particularly appropriate; mainly replacing ERRCODE_SYNTAX_ERROR by something more specific. Back-patch to 9.5, but no further; changing ERRCODE assignments in stable branches doesn't seem like a good idea.
This commit is contained in:
@ -1422,9 +1422,9 @@ BeginCopy(bool is_from,
|
||||
* in any RLS clauses.
|
||||
*
|
||||
* When this happens, we are passed in the relid of the originally
|
||||
* found relation (which we have locked). As the planner will look
|
||||
* up the relation again, we double-check here to make sure it found
|
||||
* the same one that we have locked.
|
||||
* found relation (which we have locked). As the planner will look up
|
||||
* the relation again, we double-check here to make sure it found the
|
||||
* same one that we have locked.
|
||||
*/
|
||||
if (queryRelId != InvalidOid)
|
||||
{
|
||||
@ -1603,10 +1603,12 @@ ClosePipeToProgram(CopyState cstate)
|
||||
pclose_rc = ClosePipeStream(cstate->copy_file);
|
||||
if (pclose_rc == -1)
|
||||
ereport(ERROR,
|
||||
(errmsg("could not close pipe to external command: %m")));
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not close pipe to external command: %m")));
|
||||
else if (pclose_rc != 0)
|
||||
ereport(ERROR,
|
||||
(errmsg("program \"%s\" failed",
|
||||
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
|
||||
errmsg("program \"%s\" failed",
|
||||
cstate->filename),
|
||||
errdetail_internal("%s", wait_result_to_str(pclose_rc))));
|
||||
}
|
||||
@ -1703,7 +1705,8 @@ BeginCopyTo(Relation rel,
|
||||
cstate->copy_file = OpenPipeStream(cstate->filename, PG_BINARY_W);
|
||||
if (cstate->copy_file == NULL)
|
||||
ereport(ERROR,
|
||||
(errmsg("could not execute command \"%s\": %m",
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not execute command \"%s\": %m",
|
||||
cstate->filename)));
|
||||
}
|
||||
else
|
||||
@ -1730,7 +1733,10 @@ BeginCopyTo(Relation rel,
|
||||
cstate->filename)));
|
||||
|
||||
if (fstat(fileno(cstate->copy_file), &st))
|
||||
elog(ERROR, "could not stat file \"%s\": %m", cstate->filename);
|
||||
ereport(ERROR,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not stat file \"%s\": %m",
|
||||
cstate->filename)));
|
||||
|
||||
if (S_ISDIR(st.st_mode))
|
||||
ereport(ERROR,
|
||||
@ -2271,13 +2277,13 @@ CopyFrom(CopyState cstate)
|
||||
{
|
||||
if (!ThereAreNoPriorRegisteredSnapshots() || !ThereAreNoReadyPortals())
|
||||
ereport(ERROR,
|
||||
(ERRCODE_INVALID_TRANSACTION_STATE,
|
||||
(errcode(ERRCODE_INVALID_TRANSACTION_STATE),
|
||||
errmsg("cannot perform FREEZE because of prior transaction activity")));
|
||||
|
||||
if (cstate->rel->rd_createSubid != GetCurrentSubTransactionId() &&
|
||||
cstate->rel->rd_newRelfilenodeSubid != GetCurrentSubTransactionId())
|
||||
ereport(ERROR,
|
||||
(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE,
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("cannot perform FREEZE because the table was not created or truncated in the current subtransaction")));
|
||||
|
||||
hi_options |= HEAP_INSERT_FROZEN;
|
||||
@ -2737,7 +2743,8 @@ BeginCopyFrom(Relation rel,
|
||||
cstate->copy_file = OpenPipeStream(cstate->filename, PG_BINARY_R);
|
||||
if (cstate->copy_file == NULL)
|
||||
ereport(ERROR,
|
||||
(errmsg("could not execute command \"%s\": %m",
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not execute command \"%s\": %m",
|
||||
cstate->filename)));
|
||||
}
|
||||
else
|
||||
@ -2752,7 +2759,10 @@ BeginCopyFrom(Relation rel,
|
||||
cstate->filename)));
|
||||
|
||||
if (fstat(fileno(cstate->copy_file), &st))
|
||||
elog(ERROR, "could not stat file \"%s\": %m", cstate->filename);
|
||||
ereport(ERROR,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not stat file \"%s\": %m",
|
||||
cstate->filename)));
|
||||
|
||||
if (S_ISDIR(st.st_mode))
|
||||
ereport(ERROR,
|
||||
|
Reference in New Issue
Block a user