Adaptive Framework
0.9.0
|
Files | |
file | afw_error.h |
Adaptive Framework error handling header. | |
Data Structures | |
struct | afw_error_context_s |
Adaptive Framework Error Context. More... | |
struct | afw_error_s |
Adaptive Framework Error. More... | |
struct | afw_error_footprint_s |
error footprint More... | |
struct | afw_try_s |
Macros | |
#define | AFW_ERROR_RV_SOURCE_ID_Z_NULL NULL |
Not applicable rv source id. | |
#define | AFW_ERROR_RV_SOURCE_ID_Z_apr "apr" |
APR rv source id. More... | |
#define | AFW_ERROR_RV_SOURCE_ID_Z_icu "icu" |
ICU rv source id. More... | |
#define | AFW_ERROR_CLEAR_PARTIAL(__ERROR_) |
#define | AFW_ERROR_FOOTPRINT(_footprint_) |
Set error footprint. More... | |
#define | AFW_THROW_UNHANDLED_ERROR(unhandled_error, _ERROR, _CODE, _RV_SOURCE_ID, _RV, _MESSAGE_Z) |
#define | AFW_SUCCESS(__ERROR_) ((__ERROR_)->code == afw_error_code_none) |
#define | AFW_ERROR_OCCURRED(__ERROR_) ((__ERROR_)->code != afw_error_code_none) |
#define | AFW_THROW(xctx) longjmp(((xctx)->current_try->throw_jmp_buf), (xctx)->error->code) |
#define | AFW_THROW_ERROR_Z(code, message_z, xctx) |
Macro used to set error and 0 rv in xctx and throw it. More... | |
#define | AFW_THROW_ERROR_RV_Z(code, rv_source_id, rv, message_z, xctx) |
Macro used to set error and rv in xctx and throw it. More... | |
#define | AFW_THROW_ERROR_FZ(code, xctx, format_z, ...) |
Macro used to set error and 0 rv in xctx and throw it. More... | |
#define | AFW_THROW_ERROR_RV_FZ(code, rv_source_id, rv, xctx, format_z, ...) |
Macro used to set error and rv in xctx and throw it. More... | |
#define | AFW_THROW_ERROR_VZ(code, format_z, ap, xctx) |
Macro used to set error and 0 rv in xctx and throw it. More... | |
#define | AFW_THROW_ERROR_RV_VZ(code, rv_source_id, rv, format_z, ap, xctx) |
Macro used to set error and rv in xctx and throw it. More... | |
#define | AFW_THROW_ERROR_FOOTPRINT_Z(code, message_z, xctx) |
Macro used to set error and 0 rv in xctx using line number in footprint then throw it. More... | |
#define | AFW_THROW_ERROR_FOOTPRINT_RV_Z(code, rv_source_id, rv, message_z, xctx) |
Macro used to set error and rv in xctx using line number in footprint then throw it. More... | |
#define | AFW_THROW_ERROR_FOOTPRINT_FZ(code, xctx, format_z, ...) |
Macro used to set error and 0 rv in xctx using line number in footprint then throw it. More... | |
#define | AFW_THROW_ERROR_FOOTPRINT_RV_FZ(code, rv_source_id, rv, xctx, format_z, ...) |
Macro used to set error and rv in xctx using line number in footprint then throw it. More... | |
#define | AFW_THROW_ERROR_FOOTPRINT_VZ(code, format_z, ap, xctx) |
Macro used to set error and 0 rv in xctx using line number in footprint then throw it. More... | |
#define | AFW_THROW_ERROR_FOOTPRINT_RV_VZ(code, rv_source_id, rv, format_z, ap, xctx) |
Macro used to set error and rv in xctx using line number in footprint then throw it. More... | |
#define | AFW_THROW_MEMORY_ERROR(xctx) |
#define | AFW_ERROR_INTERNAL_ON_UNHANDLED(__TRY_) |
#define | AFW_ERROR_COPY(to, from) |
Copy an error struct. More... | |
#define | AFW_ERROR_THROWN ((const afw_error_t *)&this_THROWN_ERROR) |
Access the thrown error. See AFW_TRY. More... | |
#define | AFW_TRY |
Begin an AFW TRY block. More... | |
#define | AFW_CATCH(__CODE_) |
Catch a particular error that occurs in a AFW_TRY block. More... | |
#define | AFW_CATCH_UNHANDLED |
Catch an unhandled error that occurs in a AFW_TRY block. More... | |
#define | AFW_FINALLY |
Always executed regardless of error. More... | |
#define | AFW_ENDTRY |
Ends an AFW try block. More... | |
#define | AFW_MARK_UNHANDLED |
Use in an AFW_CATCH or AFW_CATCH_UNHANDLED block to mark error as unhandled and break. More... | |
#define | afw_error_source_file(error) afw_utf8_z_source_file((error)->source_z) |
Returns value of error->source_z after last '/ 'or '\'. More... | |
Typedefs | |
typedef struct afw_error_footprint_s | afw_error_footprint_t |
error footprint More... | |
Functions | |
void | afw_error_rv_set_z (afw_error_code_t code, const afw_utf8_z_t *rv_source_id_z, int related_rv, const afw_utf8_z_t *source_z, const afw_utf8_z_t *message_z, afw_xctx_t *xctx) |
void | afw_error_set_z (afw_error_code_t code, const afw_utf8_z_t *source_z, const afw_utf8_z_t *message_z, afw_xctx_t *xctx) |
void | afw_error_rv_set_fz (afw_error_code_t code, const afw_utf8_z_t *rv_source_id_z, int related_rv, const afw_utf8_z_t *source_z, afw_xctx_t *xctx, const afw_utf8_z_t *format_z,...) |
void | afw_error_set_fz (afw_error_code_t code, const afw_utf8_z_t *source_z, afw_xctx_t *xctx, const afw_utf8_z_t *format_z,...) |
void | afw_error_rv_set_vz (afw_error_code_t code, const afw_utf8_z_t *rv_source_id_z, int related_rv, const afw_utf8_z_t *source_z, const afw_utf8_z_t *format_z, va_list ap, afw_xctx_t *xctx) |
void | afw_error_set_vz (afw_error_code_t code, const afw_utf8_z_t *source_z, const afw_utf8_z_t *format_z, va_list ap, afw_xctx_t *xctx) |
const afw_object_t * | afw_error_to_object (const afw_error_t *error, const afw_pool_t *p, afw_xctx_t *xctx) |
Create an object with error info in specified pool. More... | |
void | afw_error_add_to_object (const afw_object_t *object, const afw_error_t *error, afw_xctx_t *xctx) |
Add error info to existing object using specified pool. More... | |
afw_boolean_t | afw_error_allow_in_response (afw_error_code_t code) |
Determine if the error object for code is allowed in HTTP response. More... | |
int | afw_error_print (FILE *fp, const afw_error_t *error) |
Print error. More... | |
int | afw_error_print_with_xctx (FILE *fp, const afw_error_t *error, const afw_pool_t *p, afw_xctx_t *xctx) |
Print error when xctx is available. More... | |
void | afw_error_write_log (afw_log_priority_t priority, const afw_error_t *error, afw_xctx_t *xctx) |
Write error to environment log. More... | |
const afw_utf8_z_t * | afw_error_message (afw_xctx_t *xctx, const afw_utf8_z_t *format,...) |
Build message in xctx error message_wa and return pointer. More... | |
const afw_utf8_z_t * | afw_error_message_vz (const afw_utf8_z_t *format, va_list ap, afw_xctx_t *xctx) |
Build message in xctx error message_wa and return pointer. More... | |
afw_error_http_status (const afw_error_t *error) | |
Returns http status for error. More... | |
const afw_utf8_z_t * | afw_error_code_id_z (const afw_error_t *error) |
Returns error->code id. More... | |
const afw_utf8_t * | afw_error_to_utf8 (const afw_error_t *error, const afw_pool_t *p, afw_xctx_t *xctx) |
Convert error to utf8. More... | |
Adaptive Framework error
Typedef afw_error_code_t is defined in afw_common.h
#define AFW_CATCH | ( | __CODE_ | ) |
Catch a particular error that occurs in a AFW_TRY block.
The xctx's current_try is set to its value before entering the AFW_TRY block, so errors thrown in this AFW_CATCH block will be handle by the previous try;
Definition at line 668 of file afw_error.h.
#define AFW_CATCH_UNHANDLED |
Catch an unhandled error that occurs in a AFW_TRY block.
The xctx's current_try is set to its value before entering the AFW_TRY block, so errors thrown in this AFW_CATCH_UNHANDLED block will be handle by the previous try;
Definition at line 684 of file afw_error.h.
#define AFW_ENDTRY |
Ends an AFW try block.
Ends a TRY bock. If error was not handled, it will be rethrown so previous try can hand it. If error was handled, the xctx's error is cleared.
The xctx's current_try is set to its value before entering the AFW_TRY block, so errors thrown after this AFW_ENDTRY block will be handle by the previous try;
Always follow AFW_ENDTRY with a semicolon.
Definition at line 727 of file afw_error.h.
#define AFW_ERROR_CLEAR_PARTIAL | ( | __ERROR_ | ) |
Definition at line 138 of file afw_error.h.
#define AFW_ERROR_COPY | ( | to, | |
from | |||
) |
Copy an error struct.
to | must be sizeof(afw_error_t) |
from | is address of error to copy. |
The from error struct is copied to to and the to->message_z and to->rv_decoded_z is adjusted if they point to the corresponding wa in from.
Definition at line 539 of file afw_error.h.
#define AFW_ERROR_FOOTPRINT | ( | _footprint_ | ) |
Set error footprint.
<em>footprint</em> | is a afw_u8z_z literal associated with footprint |
This macro will set footprint.z to footprint and footprint.source_z to AFW__FILE_LINE__.
Variable with the specific name footprint of type afw_error_footprint_t must already be defined.
afw_error_footprint_t footprint;
Definition at line 171 of file afw_error.h.
#define AFW_ERROR_INTERNAL_ON_UNHANDLED | ( | __TRY_ | ) |
Definition at line 525 of file afw_error.h.
#define AFW_ERROR_OCCURRED | ( | __ERROR_ | ) | ((__ERROR_)->code != afw_error_code_none) |
Macro used to test if error->code is not afw_error_code_none.
This macro should normally only be used when an xctx is not available. AFW_THROW related macros should be used instead.
Definition at line 208 of file afw_error.h.
#define AFW_ERROR_RV_SOURCE_ID_Z_apr "apr" |
APR rv source id.
Registered in afw_environment_register_core.c.
Definition at line 40 of file afw_error.h.
#define AFW_ERROR_RV_SOURCE_ID_Z_icu "icu" |
ICU rv source id.
Registered in afw_environment_register_core.c.
Definition at line 47 of file afw_error.h.
#define afw_error_source_file | ( | error | ) | afw_utf8_z_source_file((error)->source_z) |
Returns value of error->source_z after last '/ 'or '\'.
error | struct; |
Some compilers return the full path name for FILE, but we normally just want to display the part of path after last slash.
Definition at line 879 of file afw_error.h.
#define AFW_ERROR_THROWN ((const afw_error_t *)&this_THROWN_ERROR) |
Access the thrown error. See AFW_TRY.
This should only be called in the body of AFW_CATCH and AFW_CATCH_UNHANDLED.
Definition at line 554 of file afw_error.h.
#define AFW_FINALLY |
Always executed regardless of error.
The body of AFW_FINALLY is executed after the body of the AFW_TRY and bodies of AFW_CATCH* macros, regardless of whether an error has occurred.
The xctx's current_try is set to its value before entering the AFW_TRY block, so errors thrown in this AFW_FINALLY block will be handle by the previous try;
Definition at line 702 of file afw_error.h.
#define AFW_MARK_UNHANDLED |
Use in an AFW_CATCH or AFW_CATCH_UNHANDLED block to mark error as unhandled and break.
The AFW_ENDTRY will rethrow the error.
Always follow with a semicolon (AFW_MARK_UNHANDLED;).
Definition at line 750 of file afw_error.h.
#define AFW_SUCCESS | ( | __ERROR_ | ) | ((__ERROR_)->code == afw_error_code_none) |
Macro used to test if error->code is afw_error_code_none.
This macro should normally only be used when an xctx is not available. AFW_THROW related macros should be used instead.
Definition at line 200 of file afw_error.h.
#define AFW_THROW | ( | xctx | ) | longjmp(((xctx)->current_try->throw_jmp_buf), (xctx)->error->code) |
Macro used to throw an error. The error should already be set using macro AFW_SET_ERROR().
Always follow with a semicolon ( AFW_THROW(xctx); ).
Definition at line 271 of file afw_error.h.
#define AFW_THROW_ERROR_FOOTPRINT_FZ | ( | code, | |
xctx, | |||
format_z, | |||
... | |||
) |
Macro used to set error and 0 rv in xctx using line number in footprint then throw it.
code | to be appended to afw_error_code_ |
line_number | of footprint |
xctx | of caller. |
format_z | format for error message |
... | for format_z |
Always follow with a semicolon;
Definition at line 428 of file afw_error.h.
#define AFW_THROW_ERROR_FOOTPRINT_RV_FZ | ( | code, | |
rv_source_id, | |||
rv, | |||
xctx, | |||
format_z, | |||
... | |||
) |
Macro used to set error and rv in xctx using line number in footprint then throw it.
code | to be appended to afw_error_code_ |
line_number | of footprint |
rv_source_id | to append to AFW_ERROR_RV_SOURCE_ID_Z_ |
rv | associated with rv_source_id |
xctx | of caller. |
format_z | format for error message |
... | for format_z |
Always follow with a semicolon;
Definition at line 449 of file afw_error.h.
#define AFW_THROW_ERROR_FOOTPRINT_RV_VZ | ( | code, | |
rv_source_id, | |||
rv, | |||
format_z, | |||
ap, | |||
xctx | |||
) |
Macro used to set error and rv in xctx using line number in footprint then throw it.
code | to be appended to afw_error_code_ |
line_number | of footprint |
rv_source_id | to append to AFW_ERROR_RV_SOURCE_ID_Z_ |
rv | associated with rv_source_id |
format_z | format for error message |
ap | arguments for format_z |
xctx | of caller. |
Definition at line 486 of file afw_error.h.
#define AFW_THROW_ERROR_FOOTPRINT_RV_Z | ( | code, | |
rv_source_id, | |||
rv, | |||
message_z, | |||
xctx | |||
) |
Macro used to set error and rv in xctx using line number in footprint then throw it.
code | to be appended to afw_error_code_ |
line_number | of footprint |
rv_source_id | to append to AFW_ERROR_RV_SOURCE_ID_Z_ |
rv | associated with rv_source_id_z |
message_z | error message. |
xctx | of caller. |
Always follow with a semicolon;
Definition at line 408 of file afw_error.h.
#define AFW_THROW_ERROR_FOOTPRINT_VZ | ( | code, | |
format_z, | |||
ap, | |||
xctx | |||
) |
Macro used to set error and 0 rv in xctx using line number in footprint then throw it.
code | to be appended to afw_error_code_ |
line_number | of footprint |
format_z | format for error message |
ap | arguments for format_z |
xctx | of caller. |
Always follow with a semicolon;
Definition at line 468 of file afw_error.h.
#define AFW_THROW_ERROR_FOOTPRINT_Z | ( | code, | |
message_z, | |||
xctx | |||
) |
Macro used to set error and 0 rv in xctx using line number in footprint then throw it.
code | to be appended to afw_error_code_ |
message_z | error message. |
xctx | of caller. |
Always follow with a semicolon;
Definition at line 388 of file afw_error.h.
#define AFW_THROW_ERROR_FZ | ( | code, | |
xctx, | |||
format_z, | |||
... | |||
) |
Macro used to set error and 0 rv in xctx and throw it.
code | to be appended to afw_error_code_ |
xctx | of caller. |
format_z | format for error message |
... | for format_z |
Always follow with a semicolon;
Definition at line 319 of file afw_error.h.
#define AFW_THROW_ERROR_RV_FZ | ( | code, | |
rv_source_id, | |||
rv, | |||
xctx, | |||
format_z, | |||
... | |||
) |
Macro used to set error and rv in xctx and throw it.
code | to be appended to afw_error_code_ |
rv_source_id | to append to AFW_ERROR_RV_SOURCE_ID_Z_ |
rv | associated with rv_source_id |
xctx | of caller. |
format_z | format for error message |
... | for format_z |
Always follow with a semicolon;
Definition at line 338 of file afw_error.h.
#define AFW_THROW_ERROR_RV_VZ | ( | code, | |
rv_source_id, | |||
rv, | |||
format_z, | |||
ap, | |||
xctx | |||
) |
Macro used to set error and rv in xctx and throw it.
code | to be appended to afw_error_code_ |
rv_source_id | to append to AFW_ERROR_RV_SOURCE_ID_Z_ |
rv | associated with rv_source_id |
format_z | format for error message |
ap | arguments for format_z |
xctx | of caller. |
Definition at line 371 of file afw_error.h.
#define AFW_THROW_ERROR_RV_Z | ( | code, | |
rv_source_id, | |||
rv, | |||
message_z, | |||
xctx | |||
) |
Macro used to set error and rv in xctx and throw it.
code | to be appended to afw_error_code_ |
rv_source_id | to append to AFW_ERROR_RV_SOURCE_ID_Z_ |
rv | associated with rv_source_id_z |
message_z | error message. |
xctx | of caller. |
Always follow with a semicolon;
Definition at line 301 of file afw_error.h.
#define AFW_THROW_ERROR_VZ | ( | code, | |
format_z, | |||
ap, | |||
xctx | |||
) |
Macro used to set error and 0 rv in xctx and throw it.
code | to be appended to afw_error_code_ |
format_z | format for error message |
ap | arguments for format_z |
xctx | of caller. |
Always follow with a semicolon;
Definition at line 355 of file afw_error.h.
#define AFW_THROW_ERROR_Z | ( | code, | |
message_z, | |||
xctx | |||
) |
Macro used to set error and 0 rv in xctx and throw it.
code | to be appended to afw_error_code_ |
message_z | error message. |
xctx | of caller. |
Always follow with a semicolon;
Definition at line 283 of file afw_error.h.
#define AFW_THROW_MEMORY_ERROR | ( | xctx | ) |
Macro used to set memory error in xctx and throw it.
Always follow with a semicolon;
Definition at line 499 of file afw_error.h.
#define AFW_THROW_UNHANDLED_ERROR | ( | unhandled_error, | |
_ERROR, | |||
_CODE, | |||
_RV_SOURCE_ID, | |||
_RV, | |||
_MESSAGE_Z | |||
) |
Macro used to set error and return.
This macro should normally only be used when an xctx is not available. AFW_THROW related macros should be used instead.
Definition at line 182 of file afw_error.h.
#define AFW_TRY |
Begin an AFW TRY block.
The variable name of the current xctx must be named xctx.
AFW_ERROR_THROWN can be used to access a copy of the thrown error struct (const afw_error_t *) in AFW_CATCH and AFW_CATCH_UNHANDLED.
Variable names this_ERROR_COPIED, this_THROWN_ERROR, this_TOP_OFFSET, and this_TRY are used internal by AFW TRY block macros.
— WARNING —
DO NOT use return, goto, or any other means of exiting TRY block, TRY_CATCH* blocks or AFW_FINALLY block, other than the associated AFW_ macros or the xctx's current_try will not be set correctly and AFW_FINALLY might be skipped.
AFW_TRY and associated macros are used as follows:
AFW_TRY { (Required) Beginning of TRY block, where "xctx" is the current xctx's pointer variable.
... Body of TRY.
break; (optional) goes to AFW_FINALLY if present or ENDTRY if not.
}
AFW_CATCH(error_code) { (Optional) Zero or more AFW_CATCH macros with error_code of type afw_error_codet.
... Body of CATCH.
// AFW_ERROR_THROWN can be used to access error. // example: puts(AFW_ERROR_THROWN->message_z)
break; (optional) goes to AFW_FINALLY if present or ENDTRY if not.
AFW_MARK_UNHANDLED; (Optional) Marks error as unhandled and breaks. AFW_ENDTRY will rethrow error.
}
AFW_CATCH_UNHANDLED { (Optional) AFW_CATCH_UNHANDLED macro.
... Body of CATCH executed for errors not handled by previous AFW_CATCH().
// AFW_ERROR_THROWN can be used to access error. // example: puts(AFW_ERROR_THROWN->message_z)
break; (optional) goes to AFW_FINALLY if present or ENDTRY if not.
AFW_MARK_UNHANDLED; (Optional) Marks error as unhandled and breaks. AFW_ENDTRY will rethrow error.
}
AFW_FINALLY { (Optional) AFW_FINALLY macro.
... Body of FINALLY is executed after the body of the AFW_TRY and bodies of AFW_CATCH* macros, regardless of whether an error has occurred.
break; (optional) goes to AFW_ENDTRY
}
AFW_ENDTRY; (Required) End of TRY block. The xctx's current_try will be set to its value before entering the TRY block. If error is unhandled, it will be rethrown.
Definition at line 634 of file afw_error.h.
typedef struct afw_error_footprint_s afw_error_footprint_t |
error footprint
This is used with AFW_ERROR_FOOTPRINT and AFW_THROW_ERROR_FOOTPRINT* macros
void afw_error_add_to_object | ( | const afw_object_t * | object, |
const afw_error_t * | error, | ||
afw_xctx_t * | xctx | ||
) |
Add error info to existing object using specified pool.
object | to set error properties in. |
error | info. |
xctx | of caller. |
This function leaves xctx->error unchanged if it is successful.
Definition at line 862 of file afw_error.c.
afw_boolean_t afw_error_allow_in_response | ( | afw_error_code_t | code | ) |
Determine if the error object for code is allowed in HTTP response.
code | error code. |
Definition at line 1082 of file afw_error.c.
const afw_utf8_z_t* afw_error_code_id_z | ( | const afw_error_t * | error | ) |
Returns error->code id.
error | struct. |
Definition at line 1062 of file afw_error.c.
afw_error_http_status | ( | const afw_error_t * | error | ) |
Returns http status for error.
error | struct. |
Definition at line 1041 of file afw_error.c.
const afw_utf8_z_t* afw_error_message | ( | afw_xctx_t * | xctx, |
const afw_utf8_z_t * | format, | ||
... | |||
) |
Build message in xctx error message_wa and return pointer.
xctx | of caller. |
format | Format string. |
... | List of arguments need by format string. |
This function leaves xctx->error unchanged if it is successful.
This is for use with AFW_ERROR related macros for formatted message. Messages are built in error's message_wa which is pre-allocated.
Definition at line 1023 of file afw_error.c.
const afw_utf8_z_t* afw_error_message_vz | ( | const afw_utf8_z_t * | format, |
va_list | ap, | ||
afw_xctx_t * | xctx | ||
) |
Build message in xctx error message_wa and return pointer.
format | Format string. |
ap | Argument list initialized by va_start used by format string. |
xctx | of caller. |
This function leaves xctx->error unchanged if it is successful.
This is for use with AFW_ERROR related macros for formatted message. Messages are built in error's message_wa which is pre-allocated.
Definition at line 1012 of file afw_error.c.
int afw_error_print | ( | FILE * | fp, |
const afw_error_t * | error | ||
) |
Print error.
fp | open FILE. |
error | to print. |
Definition at line 679 of file afw_error.c.
int afw_error_print_with_xctx | ( | FILE * | fp, |
const afw_error_t * | error, | ||
const afw_pool_t * | p, | ||
afw_xctx_t * | xctx | ||
) |
Print error when xctx is available.
fp | open FILE. |
error | to print. |
p | to use if needed. |
xctx | of caller. |
An evaluation backtrace will be printed if available when flag response:error:backtraceEvaluation is on.
Definition at line 783 of file afw_error.c.
const afw_object_t* afw_error_to_object | ( | const afw_error_t * | error, |
const afw_pool_t * | p, | ||
afw_xctx_t * | xctx | ||
) |
Create an object with error info in specified pool.
error | info. |
p | to use for object. |
xctx | of caller. |
This function leaves xctx->error unchanged if it is successful.
Definition at line 998 of file afw_error.c.
const afw_utf8_t* afw_error_to_utf8 | ( | const afw_error_t * | error, |
const afw_pool_t * | p, | ||
afw_xctx_t * | xctx | ||
) |
Convert error to utf8.
error | struct. |
p | to use. |
xctx | of caller. |
Definition at line 547 of file afw_error.c.
void afw_error_write_log | ( | afw_log_priority_t | priority, |
const afw_error_t * | error, | ||
afw_xctx_t * | xctx | ||
) |
Write error to environment log.
priority | level. |
error | to write. |
xctx | of caller. |
This function leaves xctx->error unchanged if it is successful.
Definition at line 639 of file afw_error.c.