Skip to content

Use proper ERRCODE #8043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/bgw/job.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ ts_bgw_job_get_share_lock(int32 bgw_job_id, MemoryContext mctx)
{
/* since we blocked for a lock , this is an unexpected condition */
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
errmsg("could not acquire share lock for job=%d", bgw_job_id)));
}
pfree(job);
Expand Down Expand Up @@ -1074,10 +1074,12 @@ zero_guc(const char *guc_name)

if (config_change == 0)
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), errmsg("guc \"%s\" does not exist", guc_name)));
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("guc \"%s\" does not exist", guc_name)));
else if (config_change < 0)
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), errmsg("could not set \"%s\" guc", guc_name)));
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("could not set \"%s\" guc", guc_name)));
}

Oid
Expand Down
3 changes: 2 additions & 1 deletion src/bgw/job_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <utils/fmgrprotos.h>
#include <utils/resowner.h>

#include "errors.h"
#include "guc.h"
#include "job_stat.h"
#include "job_stat_history.h"
Expand Down Expand Up @@ -413,7 +414,7 @@ calculate_next_start_on_failure(TimestampTz finish_time, int consecutive_failure
ErrorData *errdata = CopyErrorData();
FlushErrorState();
ereport(LOG,
(errcode(ERRCODE_INTERNAL_ERROR),
(errcode(ERRCODE_TS_UNEXPECTED),
errmsg("could not calculate next start on failure: resetting value"),
errdetail("Error: %s.", errdata->message)));
FreeErrorData(errdata);
Expand Down
3 changes: 2 additions & 1 deletion src/bgw/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <utils/timestamp.h>

#include "compat/compat.h"
#include "errors.h"
#include "extension.h"
#include "guc.h"
#include "job.h"
Expand Down Expand Up @@ -178,7 +179,7 @@ makeJobErrorData(ScheduledBgwJob *sjob, JobResult res)
{
ErrorData *edata = (ErrorData *) palloc0(sizeof(ErrorData));
edata->elevel = ERROR;
edata->sqlerrcode = ERRCODE_INTERNAL_ERROR;
edata->sqlerrcode = ERRCODE_TS_UNEXPECTED;
edata->hint = NULL;

Assert(res != JOB_SUCCESS);
Expand Down
90 changes: 58 additions & 32 deletions src/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,9 @@ ts_chunk_create_table(const Chunk *chunk, const Hypertable *ht, const char *tabl
SetUserIdAndSecContext(saved_uid, sec_ctx);
}
else
elog(ERROR, "invalid relkind \"%c\" when creating chunk", chunk->relkind);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid relkind \"%c\" when creating chunk", chunk->relkind)));

table_close(rel, AccessShareLock);

Expand Down Expand Up @@ -863,7 +865,7 @@ chunk_create_object(const Hypertable *ht, Hypercube *cube, const char *schema_na
chunk->fd.id);

if (len >= NAMEDATALEN)
elog(ERROR, "chunk table name too long");
ereport(ERROR, (errcode(ERRCODE_NAME_TOO_LONG), errmsg("chunk table name too long")));
}
else
namestrcpy(&chunk->fd.table_name, table_name);
Expand Down Expand Up @@ -1613,7 +1615,9 @@ chunk_create_from_stub(ChunkStubScanCtx *stubctx)
}

if (num_found != 1)
elog(ERROR, "no chunk found with ID %d", stubctx->stub->id);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("no chunk found with ID %d", stubctx->stub->id)));

Assert(NULL != stubctx->chunk);

Expand Down Expand Up @@ -2162,7 +2166,9 @@ get_chunks_in_time_range(Hypertable *ht, int64 older_than, int64 newer_than, Mem
errhint("The start of the time range must be before the end.")));

if (TS_HYPERTABLE_IS_INTERNAL_COMPRESSION_TABLE(ht))
elog(ERROR, "invalid operation on compressed hypertable");
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid operation on compressed hypertable")));

start_strategy = (newer_than == PG_INT64_MIN) ? InvalidStrategy : BTGreaterEqualStrategyNumber;
end_strategy = (older_than == PG_INT64_MAX) ? InvalidStrategy : BTLessStrategyNumber;
Expand Down Expand Up @@ -2409,7 +2415,9 @@ chunk_scan_find(int indexid, ScanKeyData scankey[], int nkeys, MemoryContext mct
ASSERT_IS_VALID_CHUNK(chunk);
break;
default:
elog(ERROR, "expected a single chunk, found %d", num_found);
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("expected a single chunk, found %d", num_found)));
}

return chunk;
Expand Down Expand Up @@ -3173,7 +3181,9 @@ chunk_recreate_constraint(ChunkScanCtx *ctx, ChunkStub *stub)
Chunk *chunk = chunk_create_from_stub(&stubctx);

if (stubctx.is_dropped)
elog(ERROR, "should not be recreating constraints on dropped chunks");
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("should not be recreating constraints on dropped chunks")));

ts_chunk_constraints_recreate(ctx->ht, chunk);

Expand Down Expand Up @@ -3288,7 +3298,7 @@ lock_chunk_tuple(int32 chunk_id, ItemPointer tid, FormData_chunk *form)
else
{
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
errmsg("unable to lock chunk catalog tuple, lock result is %d for chunk "
"ID (%d)",
ti->lockresult,
Expand Down Expand Up @@ -3403,7 +3413,7 @@ ts_chunk_clear_status(Chunk *chunk, int32 status)
{
/* chunk in frozen state cannot be modified */
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot modify frozen chunk status"),
errdetail("chunk id = %d attempt to clear status %d , current status %x ",
chunk->fd.id,
Expand Down Expand Up @@ -3438,7 +3448,7 @@ ts_chunk_add_status(Chunk *chunk, int32 status)
{
/* chunk in frozen state cannot be modified */
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot modify frozen chunk status"),
errdetail("chunk id = %d attempt to set status %d , current status %x ",
chunk->fd.id,
Expand All @@ -3457,7 +3467,7 @@ ts_chunk_add_status(Chunk *chunk, int32 status)
{
/* chunk in frozen state cannot be modified */
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot modify frozen chunk status"),
errdetail("chunk id = %d attempt to set status %d , current status %d ",
chunk->fd.id,
Expand Down Expand Up @@ -3490,7 +3500,7 @@ ts_chunk_set_compressed_chunk(Chunk *chunk, int32 compressed_chunk_id)
{
/* chunk in frozen state cannot be modified */
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot modify frozen chunk status"),
errdetail("chunk id = %d attempt to set status %d , current status %d ",
chunk->fd.id,
Expand All @@ -3510,7 +3520,7 @@ ts_chunk_set_compressed_chunk(Chunk *chunk, int32 compressed_chunk_id)
{
/* chunk in frozen state cannot be modified */
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot modify frozen chunk status"),
errdetail("chunk id = %d attempt to set status %d , current status %d ",
chunk->fd.id,
Expand Down Expand Up @@ -3540,7 +3550,7 @@ ts_chunk_clear_compressed_chunk(Chunk *chunk)
{
/* chunk in frozen state cannot be modified */
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot modify frozen chunk status"),
errdetail("chunk id = %d attempt to set status %d , current status %d ",
chunk->fd.id,
Expand All @@ -3560,7 +3570,7 @@ ts_chunk_clear_compressed_chunk(Chunk *chunk)
{
/* chunk in frozen state cannot be modified */
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot modify frozen chunk status"),
errdetail("chunk id = %d attempt to set status %d , current status %d ",
chunk->fd.id,
Expand Down Expand Up @@ -4100,7 +4110,9 @@ ts_chunk_drop_chunks(PG_FUNCTION_ARGS)
time_dim = hyperspace_get_open_dimension(ht->space, 0);

if (!time_dim)
elog(ERROR, "hypertable has no open partitioning dimension");
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("hypertable has no open partitioning dimension")));

time_type = ts_dimension_get_partition_type(time_dim);

Expand Down Expand Up @@ -4371,10 +4383,11 @@ ts_chunk_validate_chunk_status_for_operation(const Chunk *chunk, ChunkOperation

default:
if (throw_error)
elog(ERROR,
"%s not permitted on tiered chunk \"%s\" ",
get_chunk_operation_str(cmd),
get_rel_name(chunk_relid));
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("%s not permitted on tiered chunk \"%s\" ",
get_chunk_operation_str(cmd),
get_rel_name(chunk_relid))));
return false;
break;
}
Expand All @@ -4394,10 +4407,12 @@ ts_chunk_validate_chunk_status_for_operation(const Chunk *chunk, ChunkOperation
case CHUNK_DROP:
{
if (throw_error)
elog(ERROR,
"%s not permitted on frozen chunk \"%s\" ",
get_chunk_operation_str(cmd),
get_rel_name(chunk_relid));
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("%s not permitted on frozen chunk \"%s\" ",
get_chunk_operation_str(cmd),
get_rel_name(chunk_relid))));

return false;
break;
}
Expand Down Expand Up @@ -4582,8 +4597,11 @@ add_foreign_table_as_chunk(Oid relid, Hypertable *parent_ht)

Assert(get_rel_relkind(relid) == RELKIND_FOREIGN_TABLE);
if (hs->num_dimensions > 1)
elog(ERROR,
"cannot attach a foreign table to a hypertable that has more than 1 dimension");
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot attach a foreign table to a hypertable that has more than 1 "
"dimension")));

/* Create a new chunk based on the hypercube */
ts_catalog_database_info_become_owner(ts_catalog_database_info_get(), &sec_ctx);
chunk = ts_chunk_create_base(ts_catalog_table_next_seq_id(catalog, CHUNK),
Expand Down Expand Up @@ -4649,7 +4667,8 @@ ts_chunk_merge_on_dimension(const Hypertable *ht, Chunk *chunk, const Chunk *mer

if (chunk->hypertable_relid != merge_chunk->hypertable_relid)
ereport(ERROR,
(errmsg("cannot merge chunks from different hypertables"),
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot merge chunks from different hypertables"),
errhint("chunk 1: \"%s\", chunk 2: \"%s\"",
get_rel_name(chunk->table_id),
get_rel_name(merge_chunk->table_id))));
Expand All @@ -4666,7 +4685,8 @@ ts_chunk_merge_on_dimension(const Hypertable *ht, Chunk *chunk, const Chunk *mer
{
/* If the slices do not match (except on time dimension), we cannot merge the chunks. */
ereport(ERROR,
(errmsg("cannot merge chunks with different partitioning schemas"),
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot merge chunks with different partitioning schemas"),
errhint("chunk 1: \"%s\", chunk 2: \"%s\" have different slices on "
"dimension ID %d",
get_rel_name(chunk->table_id),
Expand All @@ -4677,15 +4697,17 @@ ts_chunk_merge_on_dimension(const Hypertable *ht, Chunk *chunk, const Chunk *mer

if (!dimension_slice_found)
ereport(ERROR,
(errmsg("cannot find slice for merging dimension"),
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("cannot find slice for merging dimension"),
errhint("chunk 1: \"%s\", chunk 2: \"%s\", dimension ID %d",
get_rel_name(chunk->table_id),
get_rel_name(merge_chunk->table_id),
dimension_id)));

if (slice->fd.range_end != merge_slice->fd.range_start)
ereport(ERROR,
(errmsg("cannot merge non-adjacent chunks over supplied dimension"),
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot merge non-adjacent chunks over supplied dimension"),
errhint("chunk 1: \"%s\", chunk 2: \"%s\", dimension ID %d",
get_rel_name(chunk->table_id),
get_rel_name(merge_chunk->table_id),
Expand All @@ -4699,7 +4721,8 @@ ts_chunk_merge_on_dimension(const Hypertable *ht, Chunk *chunk, const Chunk *mer
*/
if (num_ccs <= 0)
ereport(ERROR,
(errmsg("missing chunk constraint for dimension slice"),
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("missing chunk constraint for dimension slice"),
errhint("chunk: \"%s\", slice ID %d",
get_rel_name(chunk->table_id),
slice->fd.id)));
Expand Down Expand Up @@ -4746,7 +4769,8 @@ ts_chunk_merge_on_dimension(const Hypertable *ht, Chunk *chunk, const Chunk *mer

if (num_ccs <= 0)
ereport(ERROR,
(errmsg("missing chunk constraint for merged dimension slice"),
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("missing chunk constraint for merged dimension slice"),
errhint("chunk: \"%s\", slice ID %d",
get_rel_name(chunk->table_id),
new_slice->fd.id)));
Expand Down Expand Up @@ -4816,7 +4840,9 @@ ts_chunk_attach_osm_table_chunk(PG_FUNCTION_ARGS)
if (!name)
ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), errmsg("invalid Oid")));
else
elog(ERROR, "\"%s\" is not a hypertable", name);
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("\"%s\" is not a hypertable", name)));
}

if (get_rel_relkind(ftable_relid) == RELKIND_FOREIGN_TABLE)
Expand Down
6 changes: 4 additions & 2 deletions src/chunk_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ ts_chunk_scan_by_chunk_ids(const Hyperspace *hs, const List *chunk_ids, unsigned
/* tuplock = */ NULL);
if (slice_ptr == NULL)
{
elog(ERROR, "dimension slice %d is not found", slice_id);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("dimension slice %d is not found", slice_id)));
}
MemoryContextSwitchTo(orig_mcxt);
DimensionSlice *slice_copy = ts_dimension_slice_create(slice_ptr->fd.dimension_id,
Expand All @@ -205,7 +207,7 @@ ts_chunk_scan_by_chunk_ids(const Hyperspace *hs, const List *chunk_ids, unsigned
if (cube->num_slices == 0)
{
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("chunk %s has no dimension slices", get_rel_name(chunk->table_id))));
}

Expand Down
4 changes: 2 additions & 2 deletions src/dimension_slice.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ lock_dimension_slice_tuple(int32 dimension_slice_id, ItemPointer tid,
else
{
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
errmsg("unable to lock hypertable catalog tuple, lock result is %d for "
"hypertable "
"ID (%d)",
Expand Down Expand Up @@ -767,7 +767,7 @@ dimension_slice_tuple_delete(TupleInfo *ti, void *data)
else
{
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
errmsg("unable to lock hypertable catalog tuple, lock result is %d for "
"hypertable "
"ID (%d)",
Expand Down
8 changes: 5 additions & 3 deletions src/histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ ts_hist_sfunc(PG_FUNCTION_ARGS)
*/
nbuckets = state->nbuckets - 2;
if (nbuckets != PG_GETARG_INT32(4))
elog(ERROR, "number of buckets must not change between calls");
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("number of buckets must not change between calls")));

int32 bucket = DatumGetInt32(DirectFunctionCall4(width_bucket_float8,
val_datum,
Expand All @@ -95,11 +97,11 @@ ts_hist_sfunc(PG_FUNCTION_ARGS)
/* Increment the proper histogram bucket */
if (bucket < 0 || bucket >= state->nbuckets)
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("index %d from \"width_bucket\" out of range", bucket),
errhint("You probably have a floating point overflow.")));
if (DatumGetInt32(state->buckets[bucket]) >= PG_INT32_MAX - 1)
elog(ERROR, "overflow in histogram");
ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION), errmsg("overflow in histogram")));

state->buckets[bucket] = Int32GetDatum(DatumGetInt32(state->buckets[bucket]) + 1);

Expand Down
Loading
Loading