#include <error.hh>
Inheritance diagram for ErrorHandler:

Click elements report errors through ErrorHandler objects, which represent error collectors and printers. ErrorHandlers are passed to configure() and initialize() methods explicitly, as well as to write handlers; the click_chatter() function calls ErrorHandler implicitly.
Most ErrorHandler interactions consist of a simple call like this:
errh->error("not enough arguments (%d needed)", 5); // prints something like "not enough arguments (5 needed)\n"
This function constructs an error message string from the format arguments, annotates the string with a default error level (here, el_error), and prints it. Alternate versions take a landmark specifying where the error took place:
errh->lwarning("file.click:2", "syntax error at '%s'", word.c_str()); // prints something like "file.click:2: syntax error at 'foo'\n"
For finer control over error levels and annotations, construct an error message string directly. An error message is a string consisting of one or more lines. Each line begins with a set of optional textual annotations. The following error message has a level annotation determining how serious the error is (this one is critical, since el_critical == 2), and a landmark annotation, which specifies where the error took place (here, "x.click:1"):
"<2>{l:x.click:1}syntax error"
Click's default ErrorHandlers understand the level and landmark annotations. Users can add other arbitrary annotations, which can be useful to pass error metadata. A pair of braces ends the annotation area. This example has one user annotation eoc, and a message area that would be mistaken for an annotation were it not for the {}:
"<2>{l:x.click:1}{eoc:520}{}{not:an annotation}"
Some ErrorHandlers stack on top of others, adding useful functionality like automatic context description and prefixing. For example, ContextErrorHandler can be used to print messages like "In function 'xxx':".
FileErrorHandler errh1(stderr); ContextErrorHandler errh2(&errh1, "While counting to 2:"); errh2.error("An error occurred."); errh2.error("Another error occurred."); // prints "While counting to 2:\n" // " An error occurred.\n" // " Another error occurred.\n"
Public Types | |
| enum | Level { el_abort = -999, el_fatal = -1, el_emergency = 0, el_alert = 1, el_critical = 2, el_error = 3, el_warning = 4, el_notice = 5, el_info = 6, el_debug = 7 } |
| Error level constants. More... | |
| enum | ConversionFlags { cf_zero_pad = 1, cf_plus_positive = 2, cf_space_positive = 4, cf_left_just = 8, cf_alternate_form = 16, cf_singlequote = 32, cf_uppercase = 64, cf_signed = 128, cf_negative = 256, cf_utf8 = 1024 } |
| typedef String(*) | ConversionFunction (int flags, VA_LIST_REF_T) |
Public Member Functions | |
| ErrorHandler () | |
| Construct an ErrorHandler. | |
| void | debug (const char *fmt,...) |
| Print a debug message (level el_debug). | |
| void | message (const char *fmt,...) |
| Print an informational message (level el_info). | |
| int | warning (const char *fmt,...) |
| Print a warning message (level el_warning). | |
| int | error (const char *fmt,...) |
| Print an error message (level el_error). | |
| int | fatal (const char *fmt,...) |
| Print a fatal error message (level el_fatal). | |
| void | ldebug (const String &landmark, const char *fmt,...) |
| Print a debug message with a landmark annotation. | |
| void | lmessage (const String &landmark, const char *fmt,...) |
| Print an informational message with a landmark annotation. | |
| int | lwarning (const String &landmark, const char *fmt,...) |
| Print a warning message with a landmark annotation. | |
| int | lerror (const String &landmark, const char *fmt,...) |
| Print an error message with a landmark annotation. | |
| int | lfatal (const String &landmark, const char *fmt,...) |
| Print a fatal error message with a landmark annotation. | |
| int | xmessage (const String &str) |
| Print an annotated error message. | |
| int | xmessage (const String &anno, const String &str) |
| Print an error message, adding annotations. | |
| int | xmessage (const String &anno, const char *fmt, va_list val) |
| Format and print an error message, adding annotations. | |
| int | xmessage (const String &landmark, const String &anno, const String &str) |
| Print an error message, adding landmark and other annotations. | |
| int | xmessage (const String &landmark, const String &anno, const char *fmt, va_list val) |
| Format and print an error message, adding landmark and other annotations. | |
| int | nerrors () const |
| Return the number of errors reported via this handler. | |
| int | nwarnings () const |
| Return the number of warnings reported via this handler. | |
| void | reset_counts () |
| Reset the nwarnings() and nerrors() counts to zero. | |
| virtual String | vformat (const char *fmt, va_list val) |
| Format an error string. | |
| String | format (const char *fmt,...) |
| Format an error string. | |
| virtual String | decorate (const String &str) |
| Decorate an error message. | |
| virtual void * | emit (const String &str, void *user_data, bool more) |
| Output an error message line. | |
| virtual void | account (int level) |
| Account for an error message at level level. | |
Static Public Member Functions | |
| static ErrorHandler * | static_initialize (ErrorHandler *errh) |
| Initialize the ErrorHandler implementation. | |
| static void | static_cleanup () |
| Tear down the ErrorHandler implementation. | |
| static ErrorHandler * | default_handler () |
| Return the default ErrorHandler. | |
| static void | set_default_handler (ErrorHandler *errh) |
| Set the default ErrorHandler to errh. | |
| static ErrorHandler * | silent_handler () |
| Return the global silent ErrorHandler. | |
| static String | xformat (int default_flags, const char *fmt,...) |
| Format an error string. | |
| static String | vxformat (int default_flags, const char *fmt, va_list val) |
| static String | xformat (const char *fmt,...) |
| static String | vxformat (const char *fmt, va_list val) |
| static String | make_anno (const char *name, const String &value) |
| Create an error annotation. | |
| static String | combine_anno (const String &str, const String &anno) |
| Apply annotations from anno to every line in str. | |
| static const char * | parse_anno (const String &str, const char *begin, const char *end,...) ERRH_SENTINEL |
| Parse error annotations from a string. | |
| static const char * | skip_anno (const char *begin, const char *end) |
| Skip a string's error annotations. | |
| static String | make_landmark_anno (const String &x) |
| Return a landmark annotation equal to x. | |
| static String | clean_landmark (const String &landmark, bool colon=false) |
| Clean the landmark. | |
| static Conversion * | add_conversion (const String &name, ConversionFunction func) |
| static int | remove_conversion (Conversion *conversion) |
Static Public Attributes | |
| static const char | e_abort [] |
| Error level indicators. | |
| static const char | e_fatal [] |
| static const char | e_emergency [] |
| static const char | e_alert [] |
| static const char | e_critical [] |
| static const char | e_error [] |
| static const char | e_warning [] |
| static const char | e_warning_annotated [] |
| static const char | e_notice [] |
| static const char | e_info [] |
| static const char | e_debug [] |
| static const int | ok_result |
| static const int | error_result |
| enum ErrorHandler::Level |
Error level constants.
Lower values represent more serious errors. Levels 0-7 correspond to Linux's error levels. Negative levels request immediate exit; at user level, the Click process's exit status is the absolute value of the error level.
| ErrorHandler::ErrorHandler | ( | ) | [inline] |
Construct an ErrorHandler.
| ErrorHandler * ErrorHandler::static_initialize | ( | ErrorHandler * | errh | ) | [static] |
Initialize the ErrorHandler implementation.
| errh | default error handler |
| void ErrorHandler::static_cleanup | ( | ) | [static] |
Tear down the ErrorHandler implementation.
Deletes the internal ErrorHandlers and uninstalls default conversions.
| static ErrorHandler* ErrorHandler::default_handler | ( | ) | [inline, static] |
| void ErrorHandler::set_default_handler | ( | ErrorHandler * | errh | ) | [static] |
Set the default ErrorHandler to errh.
| static ErrorHandler* ErrorHandler::silent_handler | ( | ) | [inline, static] |
Return the global silent ErrorHandler.
| void ErrorHandler::debug | ( | const char * | fmt, | |
| ... | ||||
| ) |
Print a debug message (level el_debug).
fmt and any following arguments are parsed as by format(), and the resulting string is passed to xmessage().
| void ErrorHandler::message | ( | const char * | fmt, | |
| ... | ||||
| ) |
Print an informational message (level el_info).
| int ErrorHandler::warning | ( | const char * | fmt, | |
| ... | ||||
| ) |
Print a warning message (level el_warning).
| int ErrorHandler::error | ( | const char * | fmt, | |
| ... | ||||
| ) |
Print an error message (level el_error).
| int ErrorHandler::fatal | ( | const char * | fmt, | |
| ... | ||||
| ) |
Print a fatal error message (level el_fatal).
| void ErrorHandler::ldebug | ( | const String & | landmark, | |
| const char * | fmt, | |||
| ... | ||||
| ) |
Print a debug message with a landmark annotation.
| void ErrorHandler::lmessage | ( | const String & | landmark, | |
| const char * | fmt, | |||
| ... | ||||
| ) |
Print an informational message with a landmark annotation.
| int ErrorHandler::lwarning | ( | const String & | landmark, | |
| const char * | fmt, | |||
| ... | ||||
| ) |
Print a warning message with a landmark annotation.
| int ErrorHandler::lerror | ( | const String & | landmark, | |
| const char * | fmt, | |||
| ... | ||||
| ) |
Print an error message with a landmark annotation.
| int ErrorHandler::lfatal | ( | const String & | landmark, | |
| const char * | fmt, | |||
| ... | ||||
| ) |
Print a fatal error message with a landmark annotation.
| int ErrorHandler::xmessage | ( | const String & | str | ) |
Print an annotated error message.
Most users will call shorthand functions like error(), warning(), or lmessage(), which add relevant annotations to the message.
Print an error message, adding annotations.
| anno | annotations | |
| str | error message |
| int ErrorHandler::xmessage | ( | const String & | anno, | |
| const char * | fmt, | |||
| va_list | val | |||
| ) | [inline] |
Format and print an error message, adding annotations.
| anno | annotations | |
| fmt | error message format | |
| val | format arguments |
| int ErrorHandler::xmessage | ( | const String & | landmark, | |
| const String & | anno, | |||
| const String & | str | |||
| ) | [inline] |
Print an error message, adding landmark and other annotations.
| landmark | landmark annotation | |
| anno | additional annotations | |
| str | error message |
| int ErrorHandler::xmessage | ( | const String & | landmark, | |
| const String & | anno, | |||
| const char * | fmt, | |||
| va_list | val | |||
| ) | [inline] |
Format and print an error message, adding landmark and other annotations.
| landmark | landmark annotation | |
| anno | additional annotations | |
| fmt | error message format | |
| val | format arguments |
| int ErrorHandler::nerrors | ( | ) | const [inline] |
Return the number of errors reported via this handler.
An error is any message that contains at least one line with error level 3 (el_error) or below.
SilentErrorHandler errh1; PrefixErrorHandler errh2(&errh1, ""); assert(errh1.nerrors() == 0); errh2.error("blah"); assert(errh1.nerrors() == 1);
| int ErrorHandler::nwarnings | ( | ) | const [inline] |
Return the number of warnings reported via this handler.
A warning is any message that contains at least one line with error level 4 (el_warning), and no line with a lower level.
| void ErrorHandler::reset_counts | ( | ) | [inline] |
Reset the nwarnings() and nerrors() counts to zero.
| String ErrorHandler::xformat | ( | int | default_flags, | |
| const char * | fmt, | |||
| ... | ||||
| ) | [static] |
Format an error string.
| default_flags | default ConversionFlags | |
| fmt | printf-like format string |
%d, %i | Format an int as a decimal string. Understands flags in #0- +, field widths (including *), and precisions.
|
%hd, %ld, %lld, %zd | Format a short, long, long long, or size_t.
|
%^16d, %^32d, %^64d | Format a 16-, 32-, or 64-bit integer.
|
%o, %u, %x, %X | Format an unsigned integer in octal, decimal, or hexadecimal (with lower-case or upper-case letters).
|
%s | Format a C string (const char *). The alternate form %#s calls String::printable() on the input string. Both %#s and the alternate form %'s ensure that no part of the string is mistaken for an error annotation.
|
%c | Format a character. Prints a C-like escape if the input character isn't printable ASCII.
|
%p | Format a pointer as a hexadecimal value.
|
%e, %E, %f, %F, %g, %G | Format a double (user-level only).
|
%{...} | Call a user-provided conversion function. For example, %{ip_ptr} reads an IPAddress * argument from the argument list, and formats the pointed-to address using IPAddress::unparse().
|
%% | Format a literal % character.
|
%< | Format a left quote string. Usually prints a single quote.
|
%> | Format a right quote string. Usually prints a single quote.
|
%, | Format an apostrophe string. Usually prints a single quote.
|
| String ErrorHandler::vformat | ( | const char * | fmt, | |
| va_list | val | |||
| ) | [virtual] |
Format an error string.
| fmt | format string | |
| val | argument list |
Reimplemented in ErrorVeneer, and FileErrorHandler.
| String ErrorHandler::format | ( | const char * | fmt, | |
| ... | ||||
| ) |
Format an error string.
| fmt | format string |
Decorate an error message.
| str | error message, possibly with annotations |
Reimplemented in ErrorVeneer, ContextErrorHandler, PrefixErrorHandler, and LandmarkErrorHandler.
| void * ErrorHandler::emit | ( | const String & | str, | |
| void * | user_data, | |||
| bool | more | |||
| ) | [virtual] |
Output an error message line.
| str | error message line, possibly with annotations | |
| user_data | callback data, 0 for first line in a message | |
| more | true iff this is the last line in the current message |
str does not contain a newline, but may contain annotations, including a landmark annotation. Most ErrorHandlers use parse_anno() to extract the landmark annotation, clean it with clean_landmark(), and print it ahead of the error message proper.
ErrorHandler can handle multi-line error messages. However, the emit() function takes a line at a time; this is more useful in practice for most error message printers. The user_data and more arguments can help an ErrorHandler combine the lines of a multi-line error message. user_data is null for the first line; for second and subsequent lines, ErrorHandler passes the result of the last line's emit() call. more is true iff this is the last line in the current message.
The default emit() implementation does nothing.
Reimplemented in ErrorVeneer, and FileErrorHandler.
| virtual void ErrorHandler::account | ( | int | level | ) | [inline, virtual] |
Account for an error message at level level.
| level | minimum error level in the message |
Reimplemented in ErrorVeneer, FileErrorHandler, and BailErrorHandler.
Create an error annotation.
| name | annotation name | |
| value | annotation value |
If name equals "<>", then returns a level annotation of the form "<@a value>". value must be valid number; if it isn't, the function returns the empty string.
Otherwise, name must be a nonempty series of letters and digits. make_anno() returns a string of the form "{@a name:@a value}", where special characters in value are quoted with backslashes.
Apply annotations from anno to every line in str.
| str | string | |
| anno | annotation string |
For example:
combine_anno("Line 1\n{l:old}{x:x}Line 2\n", "<0>{l:new} ") // returns "<0>{l:new} Line 1\n<0>{l:old}{x:x} Line 2\n"
| const char * ErrorHandler::parse_anno | ( | const String & | str, | |
| const char * | begin, | |||
| const char * | end, | |||
| ... | ||||
| ) | [static] |
Parse error annotations from a string.
| str | the string | |
| begin | pointer within str to start of annotation area | |
| end | pointer to end of error region, usually str.end() |
The variable arguments portion consists of a series of pairs of C strings and value pointers, terminated by a null character pointer. Each C string is an annotation name. The corresponding annotation value, if found, is stored as a String object in the value pointer. You can also store the int value of an annotation by prefixing an annotation name with the '#' character.
For example:
String line = "{l:file:30}<4.5>error message\n"; String landmark_str, level_str; const char *s = ErrorHandler::parse_anno(line, line.begin(), line.end(), "l", &landmark_str, "<>", &level_str, (const char *) 0); // Results: s points to "error message\n", // landmark_str == "file:30", level_str == "4.5" int level; s = ErrorHandler::parse_anno(line, line.begin(), line.end(), "#<>", &level, (const char *) 0); // Results: s points to "error message\n", level_str == 4
| static const char* ErrorHandler::skip_anno | ( | const char * | begin, | |
| const char * | end | |||
| ) | [inline, static] |
Skip a string's error annotations.
| begin | pointer to start of string | |
| end | pointer one past end of string |
Return a landmark annotation equal to x.
| x | landmark |
Clean the landmark.
| landmark | landmark text | |
| colon | if true, append ": " to a nonempty landmark |
": " to the result.
const char ErrorHandler::e_abort [static] |
Error level indicators.
const int ErrorHandler::ok_result [static] |
Equals 0, used for error levels <5> and above
const int ErrorHandler::error_result [static] |
Equals -EINVAL, used for error levels <4> and below
1.5.1