GRPC Core  18.0.0
Data Structures | 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/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/profiling/timers.h"
#include "src/core/lib/slice/slice_internal.h"

Data Structures

struct  special_error_status_map
 
struct  kv_pair
 
struct  kv_pairs
 

Macros

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

Functions

void grpc_disable_error_creation ()
 
void grpc_enable_error_creation ()
 
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)
 
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_set_int (grpc_error_handle src, grpc_error_ints which, intptr_t value)
 
bool grpc_error_get_int (grpc_error_handle err, grpc_error_ints which, intptr_t *p)
 It is an error to pass nullptr as p. More...
 
grpc_error_handle grpc_error_set_str (grpc_error_handle src, grpc_error_strs which, const grpc_slice &str)
 This call takes ownership of the slice; the error is responsible for eventually unref-ing it. More...
 
bool grpc_error_get_str (grpc_error_handle err, grpc_error_strs which, grpc_slice *str)
 Returns false if the specified string is not set. More...
 
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. More...
 
const char * grpc_error_string (grpc_error_handle err)
 
std::string grpc_error_std_string (grpc_error_handle error)
 
grpc_error_handle grpc_os_error (const char *file, int line, int err, const char *call_name)
 
bool grpc_log_error (const char *what, grpc_error_handle error, const char *file, int line)
 

Variables

grpc_core::DebugOnlyTraceFlag grpc_trace_error_refcount (false, "error_refcount")
 
grpc_core::DebugOnlyTraceFlag grpc_trace_closure (false, "closure")
 
const special_error_status_map error_status_map []
 

Macro Definition Documentation

◆ DEFAULT_ERROR_CAPACITY

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

◆ SLOTS_PER_INT

#define SLOTS_PER_INT   (1)

◆ SLOTS_PER_LINKED_ERROR

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

◆ SLOTS_PER_STR

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

◆ SLOTS_PER_TIME

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

◆ SURPLUS_CAPACITY

#define SURPLUS_CAPACITY   (2 * SLOTS_PER_INT + SLOTS_PER_TIME)

Function Documentation

◆ grpc_disable_error_creation()

void grpc_disable_error_creation ( )

◆ grpc_enable_error_creation()

void grpc_enable_error_creation ( )

◆ 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.)

◆ 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.

◆ grpc_error_do_ref()

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

◆ grpc_error_do_unref()

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

◆ 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.

◆ grpc_error_get_str()

bool grpc_error_get_str ( grpc_error_handle  error,
grpc_error_strs  which,
grpc_slice s 
)

Returns false if the specified string is not set.

Caller does NOT own the slice.

◆ grpc_error_set_int()

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

◆ grpc_error_set_str()

grpc_error_handle grpc_error_set_str ( grpc_error_handle  src,
grpc_error_strs  which,
const grpc_slice str 
)

This call takes ownership of the slice; the error is responsible for eventually unref-ing it.

◆ grpc_error_std_string()

std::string grpc_error_std_string ( grpc_error_handle  error)

◆ grpc_error_string()

const char* grpc_error_string ( grpc_error_handle  err)

◆ grpc_log_error()

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

◆ grpc_os_error()

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

Variable Documentation

◆ error_status_map

const special_error_status_map error_status_map[]
Initial value:
= {
{GRPC_STATUS_OK, "", 0},
{GRPC_STATUS_RESOURCE_EXHAUSTED, "Out of memory",
strlen("Out of memory")},
{GRPC_STATUS_CANCELLED, "Cancelled",
strlen("Cancelled")},
}
@ GRPC_STATUS_CANCELLED
The operation was cancelled (typically by the caller).
Definition: status.h:31
@ GRPC_STATUS_INVALID_ARGUMENT
Client specified an invalid argument.
Definition: status.h:44
@ GRPC_STATUS_OK
Not an error; returned on success.
Definition: status.h:28
@ GRPC_STATUS_RESOURCE_EXHAUSTED
Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out ...
Definition: status.h:74

◆ grpc_trace_closure

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

◆ grpc_trace_error_refcount

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