apt  2.2.4
About: Apt (Advanced Package Tool) is a management system for software packages (Debian/Ubuntu). Release series 2.2.
  Fossies Dox: apt-2.2.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

GlobalError Class Reference

#include <error.h>

Classes

struct  Item
 
struct  MsgStack
 

Public Types

enum  MsgType {
  FATAL = 40 , ERROR = 30 , WARNING = 20 , NOTICE = 10 ,
  DEBUG = 0
}
 a message can have one of following severity More...
 

Public Member Functions

bool FatalE (const char *Function, const char *Description,...) APT_PRINTF(3) APT_COLD
 add a fatal error message with errno to the list More...
 
bool Errno (const char *Function, const char *Description,...) APT_PRINTF(3) APT_COLD
 add an Error message with errno to the list More...
 
bool WarningE (const char *Function, const char *Description,...) APT_PRINTF(3) APT_COLD
 add a warning message with errno to the list More...
 
bool NoticeE (const char *Function, const char *Description,...) APT_PRINTF(3) APT_COLD
 add a notice message with errno to the list More...
 
bool DebugE (const char *Function, const char *Description,...) APT_PRINTF(3) APT_COLD
 add a debug message with errno to the list More...
 
bool InsertErrno (MsgType const &type, const char *Function, const char *Description,...) APT_PRINTF(4) APT_COLD
 adds an errno message with the given type More...
 
bool InsertErrno (MsgType type, const char *Function, const char *Description, va_list &args, int const errsv, size_t &msgSize) APT_COLD
 adds an errno message with the given type More...
 
bool Fatal (const char *Description,...) APT_PRINTF(2) APT_COLD
 add an fatal error message to the list More...
 
bool Error (const char *Description,...) APT_PRINTF(2) APT_COLD
 add an Error message to the list More...
 
bool Warning (const char *Description,...) APT_PRINTF(2) APT_COLD
 add a warning message to the list More...
 
bool Notice (const char *Description,...) APT_PRINTF(2) APT_COLD
 add a notice message to the list More...
 
bool Debug (const char *Description,...) APT_PRINTF(2) APT_COLD
 add a debug message to the list More...
 
bool Insert (MsgType const &type, const char *Description,...) APT_PRINTF(3) APT_COLD
 adds an error message with the given type More...
 
bool Insert (MsgType type, const char *Description, va_list &args, size_t &msgSize) APT_COLD
 adds an error message with the given type More...
 
bool PendingError () const APT_PURE
 is an error in the list? More...
 
bool empty (MsgType const &threshold=WARNING) const APT_PURE
 is the list empty? More...
 
bool PopMessage (std::string &Text)
 returns and removes the first (or last) message in the list More...
 
void Discard ()
 clears the list of messages More...
 
void DumpErrors (std::ostream &out, MsgType const &threshold=WARNING, bool const &mergeStack=true)
 outputs the list of messages to the given stream More...
 
void DumpErrors (MsgType const &threshold)
 dumps the list of messages to std::cerr More...
 
void DumpErrors ()
 dumps the messages of type WARNING or higher to std::cerr More...
 
void PushToStack ()
 put the current Messages into the stack More...
 
void RevertToStack ()
 throw away all current messages More...
 
void MergeWithStack ()
 merge current and stack together More...
 
size_t StackCount () const APT_PURE
 return the deep of the stack More...
 
 GlobalError ()
 

Private Attributes

std::list< ItemMessages
 
bool PendingFlag
 
std::list< MsgStackStacks
 

Friends

APT_HIDDEN friend std::ostream & operator<< (std::ostream &out, Item i)
 

Detailed Description

Definition at line 51 of file error.h.

Member Enumeration Documentation

◆ MsgType

enum MsgType

a message can have one of following severity

Enumerator
FATAL 

Message will be printed instantly as it is likely that this error will lead to a complete crash.

ERROR 

An error does hinder the correct execution and should be corrected.

WARNING 

indicates problem that can lead to errors later on

NOTICE 

deprecation warnings, old fallback behavior, …

DEBUG 

for developers only in areas it is hard to print something directly

Definition at line 55 of file error.h.

Constructor & Destructor Documentation

◆ GlobalError()

Definition at line 43 of file error.cc.

Member Function Documentation

◆ Debug()

bool Debug ( const char *  Description,
  ... 
)

add a debug message to the list

Parameters
DescriptionFormat string for the message
Returns
false

Definition at line 120 of file error.cc.

◆ DebugE()

bool DebugE ( const char *  Function,
const char *  Description,
  ... 
)

add a debug message with errno to the list

Parameters
Functionname of the function generating the error
Descriptionformat string for the error message
Returns
false

Definition at line 63 of file error.cc.

◆ Discard()

void Discard ( )

clears the list of messages

Definition at line 205 of file error.cc.

References Messages, and PendingFlag.

Referenced by DumpErrors(), PushToStack(), and RevertToStack().

◆ DumpErrors() [1/3]

void DumpErrors ( )
inline

dumps the messages of type WARNING or higher to std::cerr

Note that all messages are discarded, displayed or not.

Definition at line 282 of file error.h.

References WARNING.

◆ DumpErrors() [2/3]

void DumpErrors ( MsgType const &  threshold)
inline

dumps the list of messages to std::cerr

Note that all messages are discarded, also the notices displayed or not.

Parameters
thresholdminimum level printed

Definition at line 270 of file error.h.

◆ DumpErrors() [3/3]

void DumpErrors ( std::ostream &  out,
MsgType const &  threshold = WARNING,
bool const &  mergeStack = true 
)

outputs the list of messages to the given stream

Note that all messages are discarded, even undisplayed ones.

Parameters
[out]outoutput stream to write the messages in
thresholdminimum level considered
mergeStackif true recursively dumps the entire stack

Definition at line 189 of file error.cc.

References Discard(), Messages, and Stacks.

◆ empty()

bool empty ( MsgType const &  threshold = WARNING) const

is the list empty?

Can be used to check if the current stack level doesn't include anything equal or more severe than a given threshold, defaulting to warning level for historic reasons.

Parameters
thresholdminimum level considered
Returns
true if the list is empty, false otherwise

Definition at line 211 of file error.cc.

References Messages, and PendingFlag.

◆ Errno()

bool Errno ( const char *  Function,
const char *  Description,
  ... 
)

add an Error message with errno to the list

Parameters
Functionname of the function generating the error
Descriptionformat string for the error message
Returns
false

Definition at line 60 of file error.cc.

◆ Error()

bool Error ( const char *  Description,
  ... 
)

add an Error message to the list

Parameters
DescriptionFormat string for the error message.
Returns
false

Definition at line 117 of file error.cc.

◆ Fatal()

bool Fatal ( const char *  Description,
  ... 
)

add an fatal error message to the list

Most of the stuff we consider as "error" is also "fatal" for the user as the application will not have the expected result, but a fatal message here means that it gets printed directly to stderr in addition to adding it to the list as the error leads sometimes to crashes and a maybe duplicated message is better than "Segfault" as the only displayed text

Parameters
DescriptionFormat string for the fatal error message.
Returns
false

Definition at line 116 of file error.cc.

◆ FatalE()

bool FatalE ( const char *  Function,
const char *  Description,
  ... 
)

add a fatal error message with errno to the list

Parameters
Functionname of the function generating the error
Descriptionformat string for the error message
Returns
false

Definition at line 59 of file error.cc.

◆ Insert() [1/2]

bool Insert ( MsgType const &  type,
const char *  Description,
  ... 
)

adds an error message with the given type

Parameters
typeof the error message
Descriptionof the error

Definition at line 124 of file error.cc.

Referenced by InsertErrno().

◆ Insert() [2/2]

bool Insert ( MsgType  type,
const char *  Description,
va_list &  args,
size_t &  msgSize 
)

adds an error message with the given type

args needs to be initialized with va_start and terminated with va_end by the caller. msgSize is also an out-parameter in case the msgSize was not enough to store the complete message.

Parameters
typeof the error message
Descriptionis the format string for args
argslist from a printf-like function
msgSizeis the size of the char[] used to store message
Returns
true if the message was added, false if not - the caller should call this method again in that case

Definition at line 138 of file error.cc.

References DEBUG, ERROR, FATAL, Messages, and PendingFlag.

◆ InsertErrno() [1/2]

bool InsertErrno ( MsgType const &  type,
const char *  Function,
const char *  Description,
  ... 
)

adds an errno message with the given type

Parameters
typeof the error message
Functionwhich failed
Descriptionof the error

Definition at line 67 of file error.cc.

◆ InsertErrno() [2/2]

bool InsertErrno ( MsgType  type,
const char *  Function,
const char *  Description,
va_list &  args,
int const  errsv,
size_t &  msgSize 
)

adds an errno message with the given type

args needs to be initialized with va_start and terminated with va_end by the caller. msgSize is also an out-parameter in case the msgSize was not enough to store the complete message.

Parameters
typeof the error message
Functionwhich failed
Descriptionis the format string for args
argslist from a printf-like function
errsvis the errno the error is for
msgSizeis the size of the char[] used to store message
Returns
true if the message was added, false if not - the caller should call this method again in that case

Definition at line 82 of file error.cc.

References Insert().

◆ MergeWithStack()

void MergeWithStack ( )

merge current and stack together

Definition at line 239 of file error.cc.

References Messages, GlobalError::MsgStack::Messages, PendingFlag, GlobalError::MsgStack::PendingFlag, and Stacks.

◆ Notice()

bool Notice ( const char *  Description,
  ... 
)

add a notice message to the list

A notice should be considered less severe than an error or a warning and can be ignored by the client without further problems for some times, but he should consider fixing the problem. This error type can be used for e.g. deprecation warnings of options.

Parameters
DescriptionFormat string for the message
Returns
false

Definition at line 119 of file error.cc.

◆ NoticeE()

bool NoticeE ( const char *  Function,
const char *  Description,
  ... 
)

add a notice message with errno to the list

Parameters
Functionname of the function generating the error
Descriptionformat string for the error message
Returns
false

Definition at line 62 of file error.cc.

◆ PendingError()

bool PendingError ( ) const
inline

is an error in the list?

Returns
true if an error is included in the list, false otherwise

Definition at line 227 of file error.h.

◆ PopMessage()

bool PopMessage ( std::string &  Text)

returns and removes the first (or last) message in the list

Parameters
[out]Textmessage of the first/last item
Returns
true if the message was an error, false otherwise

Definition at line 166 of file error.cc.

References ERROR, FATAL, Messages, msg, and PendingFlag.

◆ PushToStack()

void PushToStack ( )

put the current Messages into the stack

All "old" messages will be pushed into a stack to them later back, but for now the Message query will be empty and performs as no messages were present before.

The stack can be as deep as you want - all stack operations will only operate on the last element in the stack.

Definition at line 224 of file error.cc.

References Discard(), Messages, PendingFlag, and Stacks.

◆ RevertToStack()

void RevertToStack ( )

throw away all current messages

Definition at line 230 of file error.cc.

References Discard(), Messages, GlobalError::MsgStack::Messages, PendingFlag, GlobalError::MsgStack::PendingFlag, and Stacks.

◆ StackCount()

size_t StackCount ( ) const
inline

return the deep of the stack

Definition at line 304 of file error.h.

◆ Warning()

bool Warning ( const char *  Description,
  ... 
)

add a warning message to the list

A warning should be considered less severe than an error and may be ignored by the client.

Parameters
DescriptionFormat string for the message
Returns
false

Definition at line 118 of file error.cc.

◆ WarningE()

bool WarningE ( const char *  Function,
const char *  Description,
  ... 
)

add a warning message with errno to the list

A warning should be considered less severe than an error and may be ignored by the client.

Parameters
FunctionName of the function generates the warning.
DescriptionFormat string for the warning message.
Returns
false

Definition at line 61 of file error.cc.

Friends And Related Function Documentation

◆ operator<<

APT_HIDDEN friend std::ostream& operator<< ( std::ostream &  out,
GlobalError::Item  i 
)
friend

Definition at line 248 of file error.cc.

Member Data Documentation

◆ Messages

std::list<Item> Messages
private

◆ PendingFlag

bool PendingFlag
private

Definition at line 324 of file error.h.

Referenced by Discard(), empty(), Insert(), MergeWithStack(), PopMessage(), PushToStack(), and RevertToStack().

◆ Stacks

std::list<MsgStack> Stacks
private

Definition at line 334 of file error.h.

Referenced by DumpErrors(), MergeWithStack(), PushToStack(), and RevertToStack().


The documentation for this class was generated from the following files: