From 0a32c195a783b027fc052f2e845cf473f2330402 Mon Sep 17 00:00:00 2001 From: Haoyu Huang Date: Wed, 23 Apr 2025 15:08:05 -0700 Subject: [PATCH 1/2] PG16 add sql error code hook (#32) see https://github.com/databricks-eng/postgres/pull/30 --- src/backend/utils/error/elog.c | 9 +++++++++ src/include/utils/elog.h | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 155d8519a74..27668c917e9 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -96,6 +96,10 @@ ErrorContextCallback *error_context_stack = NULL; sigjmp_buf *PG_exception_stack = NULL; +/* BEGIN_HADRON */ +SqlErrorCode_hook_type SqlErrorCode_hook = NULL; +/* END_HADRON */ + extern bool redirection_done; /* @@ -857,6 +861,11 @@ matches_backtrace_functions(const char *funcname) int errcode(int sqlerrcode) { +/* BEGIN_HADRON */ + if (SqlErrorCode_hook != NULL) { + SqlErrorCode_hook(sqlerrcode); + } +/* END_HADRON */ ErrorData *edata = &errordata[errordata_stack_depth]; /* we don't bother incrementing recursion_depth */ diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h index 8bb55e5b3cc..20892425967 100644 --- a/src/include/utils/elog.h +++ b/src/include/utils/elog.h @@ -429,6 +429,11 @@ extern PGDLLIMPORT ErrorContextCallback *error_context_stack; extern PGDLLIMPORT sigjmp_buf *PG_exception_stack; +/* BEGIN_HADRON */ +typedef void (*SqlErrorCode_hook_type) (int sqlerrcode); +extern PGDLLIMPORT SqlErrorCode_hook_type SqlErrorCode_hook; +/* END_HADRON */ + /* Stuff that error handlers might want to use */ From 21cd2951f51b7bf3e9962272c5aa2a4a3b800aa1 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Tue, 22 Jul 2025 12:54:15 +0200 Subject: [PATCH 2/2] Review. --- src/backend/utils/error/elog.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 27668c917e9..30a3a1e698e 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -96,9 +96,9 @@ ErrorContextCallback *error_context_stack = NULL; sigjmp_buf *PG_exception_stack = NULL; -/* BEGIN_HADRON */ +/* BEGIN_NEON */ SqlErrorCode_hook_type SqlErrorCode_hook = NULL; -/* END_HADRON */ +/* END_NEON */ extern bool redirection_done; @@ -861,11 +861,11 @@ matches_backtrace_functions(const char *funcname) int errcode(int sqlerrcode) { -/* BEGIN_HADRON */ +/* BEGIN_NEON */ if (SqlErrorCode_hook != NULL) { SqlErrorCode_hook(sqlerrcode); } -/* END_HADRON */ +/* END_NEON */ ErrorData *edata = &errordata[errordata_stack_depth]; /* we don't bother incrementing recursion_depth */