Classes | Macros | Functions | Variables
error.cc File Reference
#include <grpc/support/port_platform.h>
#include "src/core/lib/iomgr/error.h"
#include <inttypes.h>
#include <string.h>
#include <grpc/impl/codegen/status.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/error_internal.h"
#include "src/core/lib/slice/slice_internal.h"
Include dependency graph for error.cc:

Go to the source code of this file.

Classes

struct  kv_pair
 
struct  kv_pairs
 
struct  special_error_status_map
 

Macros

#define DEFAULT_ERROR_CAPACITY   (SLOTS_PER_INT + (SLOTS_PER_STR * 2) + SLOTS_PER_TIME)
 
#define SLOTS_PER_INT   (1)
 
#define SLOTS_PER_LINKED_ERROR   (sizeof(grpc_linked_error) / sizeof(intptr_t))
 
#define SLOTS_PER_STR   (sizeof(grpc_slice) / sizeof(intptr_t))
 
#define SLOTS_PER_TIME   (sizeof(gpr_timespec) / sizeof(intptr_t))
 
#define SURPLUS_CAPACITY   (2 * SLOTS_PER_INT + SLOTS_PER_TIME)
 

Functions

static void add_errs (grpc_error_handle err, char **s, size_t *sz, size_t *cap)
 
static void append_chr (char c, char **s, size_t *sz, size_t *cap)
 
static void append_esc_str (const uint8_t *str, size_t len, char **s, size_t *sz, size_t *cap)
 
static void append_kv (kv_pairs *kvs, char *key, char *value)
 
static void append_str (const char *str, char **s, size_t *sz, size_t *cap)
 
static int cmp_kvs (const void *a, const void *b)
 
static void collect_ints_kvs (grpc_error_handle err, kv_pairs *kvs)
 
static void collect_strs_kvs (grpc_error_handle err, kv_pairs *kvs)
 
static void collect_times_kvs (grpc_error_handle err, kv_pairs *kvs)
 
static grpc_error_handle copy_error_and_unref (grpc_error_handle in)
 
static void error_destroy (grpc_error_handle err)
 
static const char * error_int_name (grpc_error_ints key)
 
static const char * error_str_name (grpc_error_strs key)
 
static const char * error_time_name (grpc_error_times key)
 
static char * errs_string (grpc_error_handle err)
 
static char * finish_kvs (kv_pairs *kvs)
 
static char * fmt_int (intptr_t p)
 
static char * fmt_str (const grpc_slice &slice)
 
static char * fmt_time (gpr_timespec tm)
 
static uint8_t get_placement (grpc_error_handle *err, size_t size)
 
void grpc_disable_error_creation ()
 
void grpc_enable_error_creation ()
 
grpc_error_handle grpc_error_add_child (grpc_error_handle src, grpc_error_handle child)
 
grpc_error_handle grpc_error_create (const char *file, int line, const grpc_slice &desc, grpc_error_handle *referencing, size_t num_referencing)
 Create an error - but use GRPC_ERROR_CREATE instead. More...
 
grpc_error_handle grpc_error_do_ref (grpc_error_handle err, const char *file, int line)
 
void grpc_error_do_unref (grpc_error_handle err, const char *file, int line)
 
bool grpc_error_get_int (grpc_error_handle err, grpc_error_ints which, intptr_t *p)
 
bool grpc_error_get_str (grpc_error_handle err, grpc_error_strs which, std::string *s)
 Returns false if the specified string is not set. More...
 
grpc_error_handle grpc_error_set_int (grpc_error_handle src, grpc_error_ints which, intptr_t value)
 
grpc_error_handle grpc_error_set_str (grpc_error_handle src, grpc_error_strs which, absl::string_view str)
 
std::string grpc_error_std_string (grpc_error_handle error)
 
const char * grpc_error_string (grpc_error_handle err)
 
bool grpc_log_error (const char *what, grpc_error_handle error, const char *file, int line)
 
grpc_error_handle grpc_os_error (const char *file, int line, int err, const char *call_name)
 
static void internal_add_error (grpc_error_handle *err, grpc_error_handle new_err)
 
static void internal_set_int (grpc_error_handle *err, grpc_error_ints which, intptr_t value)
 
static void internal_set_str (grpc_error_handle *err, grpc_error_strs which, const grpc_slice &value)
 
static void internal_set_time (grpc_error_handle *err, grpc_error_times which, gpr_timespec value)
 
static char * key_int (grpc_error_ints which)
 
static char * key_str (grpc_error_strs which)
 
static char * key_time (grpc_error_times which)
 
static void ref_errs (grpc_error_handle err)
 
static void ref_strs (grpc_error_handle err)
 
static void unref_errs (grpc_error_handle err)
 
static void unref_strs (grpc_error_handle err)
 

Variables

static const char * cancelled_error_string = "\"CANCELLED\""
 
const special_error_status_map error_status_map []
 
static gpr_atm g_error_creation_allowed = true
 
grpc_core::DebugOnlyTraceFlag grpc_trace_closure (false, "closure")
 
grpc_core::DebugOnlyTraceFlag grpc_trace_error_refcount (false, "error_refcount")
 
static const char * no_error_string = "\"OK\""
 
static const char * oom_error_string = "\"RESOURCE_EXHAUSTED\""
 

Macro Definition Documentation

◆ DEFAULT_ERROR_CAPACITY

#define DEFAULT_ERROR_CAPACITY   (SLOTS_PER_INT + (SLOTS_PER_STR * 2) + SLOTS_PER_TIME)

Definition at line 483 of file error.cc.

◆ SLOTS_PER_INT

#define SLOTS_PER_INT   (1)

Definition at line 476 of file error.cc.

◆ SLOTS_PER_LINKED_ERROR

#define SLOTS_PER_LINKED_ERROR   (sizeof(grpc_linked_error) / sizeof(intptr_t))

Definition at line 479 of file error.cc.

◆ SLOTS_PER_STR

#define SLOTS_PER_STR   (sizeof(grpc_slice) / sizeof(intptr_t))

Definition at line 477 of file error.cc.

◆ SLOTS_PER_TIME

#define SLOTS_PER_TIME   (sizeof(gpr_timespec) / sizeof(intptr_t))

Definition at line 478 of file error.cc.

◆ SURPLUS_CAPACITY

#define SURPLUS_CAPACITY   (2 * SLOTS_PER_INT + SLOTS_PER_TIME)

Definition at line 487 of file error.cc.

Function Documentation

◆ add_errs()

static void add_errs ( grpc_error_handle  err,
char **  s,
size_t *  sz,
size_t *  cap 
)
static

Definition at line 855 of file error.cc.

◆ append_chr()

static void append_chr ( char  c,
char **  s,
size_t *  sz,
size_t *  cap 
)
static

Definition at line 713 of file error.cc.

◆ append_esc_str()

static void append_esc_str ( const uint8_t str,
size_t  len,
char **  s,
size_t *  sz,
size_t *  cap 
)
static

Definition at line 727 of file error.cc.

◆ append_kv()

static void append_kv ( kv_pairs kvs,
char *  key,
char *  value 
)
static

Definition at line 765 of file error.cc.

◆ append_str()

static void append_str ( const char *  str,
char **  s,
size_t *  sz,
size_t *  cap 
)
static

Definition at line 721 of file error.cc.

◆ cmp_kvs()

static int cmp_kvs ( const void *  a,
const void *  b 
)
static

Definition at line 882 of file error.cc.

◆ collect_ints_kvs()

static void collect_ints_kvs ( grpc_error_handle  err,
kv_pairs kvs 
)
static

Definition at line 786 of file error.cc.

◆ collect_strs_kvs()

static void collect_strs_kvs ( grpc_error_handle  err,
kv_pairs kvs 
)
static

Definition at line 810 of file error.cc.

◆ collect_times_kvs()

static void collect_times_kvs ( grpc_error_handle  err,
kv_pairs kvs 
)
static

Definition at line 845 of file error.cc.

◆ copy_error_and_unref()

static grpc_error_handle copy_error_and_unref ( grpc_error_handle  in)
static

Definition at line 563 of file error.cc.

◆ error_destroy()

static void error_destroy ( grpc_error_handle  err)
static

Definition at line 342 of file error.cc.

◆ error_int_name()

static const char* error_int_name ( grpc_error_ints  key)
static

Definition at line 224 of file error.cc.

◆ error_str_name()

static const char* error_str_name ( grpc_error_strs  key)
static

Definition at line 262 of file error.cc.

◆ error_time_name()

static const char* error_time_name ( grpc_error_times  key)
static

Definition at line 292 of file error.cc.

◆ errs_string()

static char* errs_string ( grpc_error_handle  err)
static

Definition at line 871 of file error.cc.

◆ finish_kvs()

static char* finish_kvs ( kv_pairs kvs)
static

Definition at line 888 of file error.cc.

◆ fmt_int()

static char* fmt_int ( intptr_t  p)
static

Definition at line 780 of file error.cc.

◆ fmt_str()

static char* fmt_str ( const grpc_slice slice)
static

Definition at line 800 of file error.cc.

◆ fmt_time()

static char * fmt_time ( gpr_timespec  tm)
static

Definition at line 824 of file error.cc.

◆ get_placement()

static uint8_t get_placement ( grpc_error_handle err,
size_t  size 
)
static

Definition at line 370 of file error.cc.

◆ grpc_disable_error_creation()

void grpc_disable_error_creation ( )

Definition at line 45 of file error.cc.

◆ grpc_enable_error_creation()

void grpc_enable_error_creation ( )

Definition at line 49 of file error.cc.

◆ grpc_error_add_child()

grpc_error_handle grpc_error_add_child ( grpc_error_handle  src,
grpc_error_handle  child 
)

Add a child error: an error that is believed to have contributed to this error occurring. Allows root causing high level errors from lower level errors that contributed to them. The src error takes ownership of the child error.

Edge Conditions - 1) If either of src or child is GRPC_ERROR_NONE, returns a reference to the other argument. 2) If both src and child are GRPC_ERROR_NONE, returns GRPC_ERROR_NONE. 3) If src and child point to the same error, returns a single reference. (Note that, 2 references should have been received to the error in this case.)

Definition at line 678 of file error.cc.

◆ grpc_error_create()

grpc_error_handle grpc_error_create ( const char *  file,
int  line,
const grpc_slice desc,
grpc_error_handle referencing,
size_t  num_referencing 
)

Create an error - but use GRPC_ERROR_CREATE instead.

Definition at line 489 of file error.cc.

◆ grpc_error_do_ref()

grpc_error_handle grpc_error_do_ref ( grpc_error_handle  err,
const char *  file,
int  line 
)

Definition at line 303 of file error.cc.

◆ grpc_error_do_unref()

void grpc_error_do_unref ( grpc_error_handle  err,
const char *  file,
int  line 
)

Definition at line 352 of file error.cc.

◆ grpc_error_get_int()

bool grpc_error_get_int ( grpc_error_handle  error,
grpc_error_ints  which,
intptr_t p 
)

It is an error to pass nullptr as p. Caller should allocate a phony intptr_t for p, even if the value of p is not used.

Definition at line 635 of file error.cc.

◆ grpc_error_get_str()

bool grpc_error_get_str ( grpc_error_handle  err,
grpc_error_strs  which,
std::string *  s 
)

Returns false if the specified string is not set.

Definition at line 659 of file error.cc.

◆ grpc_error_set_int()

grpc_error_handle grpc_error_set_int ( grpc_error_handle  src,
grpc_error_ints  which,
intptr_t  value 
)

Definition at line 613 of file error.cc.

◆ grpc_error_set_str()

grpc_error_handle grpc_error_set_str ( grpc_error_handle  src,
grpc_error_strs  which,
absl::string_view  str 
)

Definition at line 650 of file error.cc.

◆ grpc_error_std_string()

std::string grpc_error_std_string ( grpc_error_handle  error)

Definition at line 944 of file error.cc.

◆ grpc_error_string()

const char * grpc_error_string ( grpc_error_handle  err)

Definition at line 910 of file error.cc.

◆ grpc_log_error()

bool grpc_log_error ( const char *  what,
grpc_error_handle  error,
const char *  file,
int  line 
)

Definition at line 981 of file error.cc.

◆ grpc_os_error()

grpc_error_handle grpc_os_error ( const char *  file,
int  line,
int  err,
const char *  call_name 
)

Definition at line 948 of file error.cc.

◆ internal_add_error()

static void internal_add_error ( grpc_error_handle err,
grpc_error_handle  new_err 
)
static

Definition at line 452 of file error.cc.

◆ internal_set_int()

static void internal_set_int ( grpc_error_handle err,
grpc_error_ints  which,
intptr_t  value 
)
static

Definition at line 397 of file error.cc.

◆ internal_set_str()

static void internal_set_str ( grpc_error_handle err,
grpc_error_strs  which,
const grpc_slice value 
)
static

Definition at line 412 of file error.cc.

◆ internal_set_time()

static void internal_set_time ( grpc_error_handle err,
grpc_error_times  which,
gpr_timespec  value 
)
static

Definition at line 433 of file error.cc.

◆ key_int()

static char* key_int ( grpc_error_ints  which)
static

Definition at line 776 of file error.cc.

◆ key_str()

static char* key_str ( grpc_error_strs  which)
static

Definition at line 796 of file error.cc.

◆ key_time()

static char* key_time ( grpc_error_times  which)
static

Definition at line 820 of file error.cc.

◆ ref_errs()

static void ref_errs ( grpc_error_handle  err)
static

Definition at line 553 of file error.cc.

◆ ref_strs()

static void ref_strs ( grpc_error_handle  err)
static

Definition at line 543 of file error.cc.

◆ unref_errs()

static void unref_errs ( grpc_error_handle  err)
static

Definition at line 320 of file error.cc.

◆ unref_strs()

static void unref_strs ( grpc_error_handle  err)
static

Definition at line 332 of file error.cc.

Variable Documentation

◆ cancelled_error_string

const char* cancelled_error_string = "\"CANCELLED\""
static

Definition at line 702 of file error.cc.

◆ error_status_map

const special_error_status_map error_status_map[]
Initial value:
= {
{GRPC_STATUS_OK, "", 0},
{GRPC_STATUS_RESOURCE_EXHAUSTED, "RESOURCE_EXHAUSTED",
strlen("RESOURCE_EXHAUSTED")},
{GRPC_STATUS_CANCELLED, "CANCELLED",
strlen("CANCELLED")},
}

Definition at line 625 of file error.cc.

◆ g_error_creation_allowed

gpr_atm g_error_creation_allowed = true
static

Definition at line 43 of file error.cc.

◆ grpc_trace_closure

grpc_core::DebugOnlyTraceFlag grpc_trace_closure(false, "closure")

◆ grpc_trace_error_refcount

grpc_core::DebugOnlyTraceFlag grpc_trace_error_refcount(false, "error_refcount")

◆ no_error_string

const char* no_error_string = "\"OK\""
static

Definition at line 700 of file error.cc.

◆ oom_error_string

const char* oom_error_string = "\"RESOURCE_EXHAUSTED\""
static

Definition at line 701 of file error.cc.

GRPC_STATUS_CANCELLED
@ GRPC_STATUS_CANCELLED
Definition: include/grpc/impl/codegen/status.h:33
GRPC_STATUS_INVALID_ARGUMENT
@ GRPC_STATUS_INVALID_ARGUMENT
Definition: include/grpc/impl/codegen/status.h:46
GRPC_STATUS_RESOURCE_EXHAUSTED
@ GRPC_STATUS_RESOURCE_EXHAUSTED
Definition: include/grpc/impl/codegen/status.h:76
GRPC_STATUS_OK
@ GRPC_STATUS_OK
Definition: include/grpc/impl/codegen/status.h:30


grpc
Author(s):
autogenerated on Fri May 16 2025 03:01:12