Skip to content
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

Add errdetail() calls to save_advice #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
42 changes: 24 additions & 18 deletions index_adviser/index_adviser.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,29 @@ PG_MODULE_MAGIC;
/* IND_ADV_TABL does Not Exist */
#define IND_ADV_ERROR_NE "relation \""IND_ADV_TABL"\" does not exist."

/* IND_ADV_TABL is Not a Table or a View */
#define IND_ADV_ERROR_NTV "\""IND_ADV_TABL"\" is not a table or view."

#define IND_ADV_ERROR_DETAIL \
"Index Adviser uses \""IND_ADV_TABL"\" table to store it's advisory. You" \
#define IND_ADV_ERROR_DETAIL_NE \
"Index Adviser uses \""IND_ADV_TABL"\" table to store its advisory. You" \
" should have INSERT permissions on a table or an (INSERT-able) view named"\
" \""IND_ADV_TABL"\". Also, make sure that you are NOT running the Index" \
" Adviser under a read-only transaction."

#define IND_ADV_ERROR_HINT \
#define IND_ADV_ERROR_HINT_NE \
"Please create the \""IND_ADV_TABL"\" table using the script provided in" \
" pg_advise_index contrib module."

/* IND_ADV_TABL is Not a Table or a View */
#define IND_ADV_ERROR_NTV "\""IND_ADV_TABL"\" is not a table or view."

#define IND_ADV_ERROR_DETAIL_NTV \
"Index Adviser uses \""IND_ADV_TABL"\" table to store its advisory." \
" \""IND_ADV_TABL"\" should be a table or an (INSERT-able) view on which you" \
" have INSERT permissions."

#define IND_ADV_ERROR_HINT_NTV \
"Please drop the existing \""IND_ADV_TABL"\" entity and create the" \
" \""IND_ADV_TABL"\" table using the script provided in" \
" pg_advise_index contrib module."

/* *****************************************************************************
* forward declarations of local-only functions
* ****************************************************************************/
Expand Down Expand Up @@ -597,14 +607,6 @@ index_adviser( Query* queryCopy,
/* reset our 'running' state... */
--SuppressRecursion;

/*
* Add a detailed explanation to the ERROR. Note that these function
* calls will overwrite the DETAIL and HINT that are already
* associated (if any) with this ERROR. XXX consider errcontext().
*/
errdetail( IND_ADV_ERROR_DETAIL );
errhint( IND_ADV_ERROR_HINT );

/* ... and re-throw the ERROR */
PG_RE_THROW();
}
Expand Down Expand Up @@ -1018,10 +1020,13 @@ save_advice( List* candidates )
{
relation_close(advise_rel, AccessShareLock);

/* FIXME: add errdetail() and/or errcontext() calls here. */
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg( IND_ADV_ERROR_NTV )));
errmsg( IND_ADV_ERROR_NTV ),
errdetail( IND_ADV_ERROR_DETAIL_NTV ),
errhint( IND_ADV_ERROR_HINT_NTV ),
errcontext( "during save_advice, advise_rel->rd_rel->relkind = %c",
advise_rel->rd_rel->relkind )));
}

relation_close(advise_rel, AccessShareLock);
Expand All @@ -1048,10 +1053,11 @@ save_advice( List* candidates )
}
else
{
/* FIXME: add errdetail() and/or errcontext() calls here. */
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg( IND_ADV_ERROR_NE )));
errmsg( IND_ADV_ERROR_NE ),
errdetail( IND_ADV_ERROR_DETAIL_NE ),
errhint( IND_ADV_ERROR_HINT_NE )));
}

initStringInfo( &query );
Expand Down