Add an error mode to disable creation

pull/15676/head
ncteisen 7 years ago
parent f03344e73a
commit 3fa24f6e90
  1. 12
      src/core/lib/iomgr/error.cc
  2. 5
      src/core/lib/iomgr/error.h

@ -312,6 +312,12 @@ static void internal_add_error(grpc_error** err, grpc_error* new_err) {
// It is very common to include and extra int and string in an error
#define SURPLUS_CAPACITY (2 * SLOTS_PER_INT + SLOTS_PER_TIME)
static bool g_error_creation_allowed = true;
void grpc_disable_error_creation() { g_error_creation_allowed = false; }
void grpc_enable_error_creation() { g_error_creation_allowed = true; }
grpc_error* grpc_error_create(const char* file, int line, grpc_slice desc,
grpc_error** referencing,
size_t num_referencing) {
@ -326,6 +332,12 @@ grpc_error* grpc_error_create(const char* file, int line, grpc_slice desc,
return GRPC_ERROR_OOM;
}
#ifndef NDEBUG
if (!g_error_creation_allowed) {
gpr_log(GPR_ERROR,
"Error creation occurred when error creation was disabled [%s:%d]",
file, line);
abort();
}
if (grpc_trace_error_refcount.enabled()) {
gpr_log(GPR_DEBUG, "%p create [%s:%d]", err, file, line);
}

@ -123,6 +123,11 @@ typedef enum {
#define GRPC_ERROR_OOM ((grpc_error*)2)
#define GRPC_ERROR_CANCELLED ((grpc_error*)4)
// debug only toggles that allow for a sanity to check that ensures we will
// never create any errors in the per-RPC hotpath.
void grpc_disable_error_creation();
void grpc_enable_error_creation();
const char* grpc_error_string(grpc_error* error);
/// Create an error - but use GRPC_ERROR_CREATE instead

Loading…
Cancel
Save