if (!OidIsValid(get_role_oid(user_name_reset, false))) { ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), errmsg("role \"%s\" does not exist", user_name_reset))); }
/* ---------- * New-style error reporting API: to be used in this way: * ereport(ERROR, * (errcode(ERRCODE_UNDEFINED_CURSOR), * errmsg("portal \"%s\" not found", stmt->portalname), * ... other errxxx() fields as needed ...)); * * The error level is required, and so is a primary error message (errmsg * or errmsg_internal). All else is optional. errcode() defaults to * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is * NOTICE or below. * * ereport_domain() allows a message domain to be specified, for modules that * wish to use a different message catalog from the backend's. To avoid having * one copy of the default text domain per .o file, we define it as NULL here * and have errstart insert the default text domain. Modules can either use * ereport_domain() directly, or preferably they can override the TEXTDOMAIN * macro. * ---------- */ #define ereport_domain(elevel, domain, rest) \ (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain) ? (errfinish rest) : (void)0)
/* * errcode --- add SQLSTATE error code to the current error * * The code is expected to be represented as per MAKE_SQLSTATE(). */ interrcode(int sqlerrcode) { ErrorData* edata = &t_thrd.log_cxt.errordata[t_thrd.log_cxt.errordata_stack_depth];
/* we don't bother incrementing t_thrd.log_cxt.recursion_depth */ CHECK_STACK_DEPTH();
edata->sqlerrcode = sqlerrcode;
return0; /* return value does not matter */ } /* * errmsg --- add a primary error message text to the current error * * In addition to the usual %-escapes recognized by printf, "%m" in * fmt is replaced by the error message for the caller's value of errno. * * Note: no newline is needed at the end of the fmt string, since * ereport will provide one for the output methods that need it. */ interrmsg(constchar* fmt, ...) { ErrorData* edata = &t_thrd.log_cxt.errordata[t_thrd.log_cxt.errordata_stack_depth]; MemoryContext oldcontext;
/* ---------- * API for catching ereport(ERROR) exits. Use these macros like so: * * PG_TRY(); * { * ... code that might throw ereport(ERROR) ... * } * PG_CATCH(); * { * ... error recovery code ... * } * PG_END_TRY(); * * (The braces are not actually necessary, but are recommended so that * pg_indent will indent the construct nicely.) The error recovery code * can optionally do PG_RE_THROW() to propagate the same error outwards. * * Note: while the system will correctly propagate any new ereport(ERROR) * occurring in the recovery section, there is a small limit on the number * of levels this will work for. It's best to keep the error recovery * section simple enough that it can't generate any new errors, at least * not before popping the error stack. * * Note: an ereport(FATAL) will not be caught by this construct; control will * exit straight through proc_exit(). Therefore, do NOT put any cleanup * of non-process-local resources into the error recovery section, at least * not without taking thought for what will happen during ereport(FATAL). * The PG_ENSURE_ERROR_CLEANUP macros provided by storage/ipc.h may be * helpful in such cases. * * Note: Don't execute statements such as break, continue, goto, or return in * PG_TRY. If you need to use these statements, you must recovery * PG_exception_stack first. * ---------- */ #define PG_TRY() \ do { \ sigjmp_buf* save_exception_stack = t_thrd.log_cxt.PG_exception_stack; \ ErrorContextCallback* save_context_stack = t_thrd.log_cxt.error_context_stack; \ sigjmp_buf local_sigjmp_buf; \ int tryCounter, *oldTryCounter = NULL; \ if (sigsetjmp(local_sigjmp_buf, 0) == 0) { \ t_thrd.log_cxt.PG_exception_stack = &local_sigjmp_buf; \ oldTryCounter = gstrace_tryblock_entry(&tryCounter)