libfoedus-core
FOEDUS Core Library
foedus::FixedErrorStack Class Reference

Representation of ErrorStack that can be copied to other processes and even serialized to files. More...

Detailed Description

Representation of ErrorStack that can be copied to other processes and even serialized to files.

ErrorStack contains char*, so can't be trivially passed to other processes or serialized. This object is used in such a situation. It does string copying and (if too long) truncation, so do not use this unless required.

Definition at line 41 of file fixed_error_stack.hpp.

#include <fixed_error_stack.hpp>

Public Types

typedef assorted::FixedString< 124 > FixedFileName
 
typedef assorted::FixedString< 124 > FixedFuncName
 
typedef assorted::FixedString< 508 > FixedErrorMessage
 

Public Member Functions

 FixedErrorStack ()
 Empty constructor. More...
 
 FixedErrorStack (const ErrorStack &src)
 Copy the content of the given ErrorStack. More...
 
FixedErrorStackoperator= (const ErrorStack &src)
 Assignment operator. More...
 
bool is_error () const
 Returns if this return code is not kErrorCodeOk. More...
 
ErrorCode get_error_code () const
 Return the integer error code. More...
 
const char * get_message () const
 Returns the error message inferred by the error code. More...
 
const FixedErrorMessageget_custom_message () const
 Returns the custom error message. More...
 
uint16_t get_stack_depth () const
 Returns the depth of stack this error code has collected. More...
 
uint32_t get_linenum (uint16_t stack_index) const
 Returns the line number of the given stack position. More...
 
const FixedFileNameget_filename (uint16_t stack_index) const
 Returns the file name of the given stack position. More...
 
const FixedFuncNameget_func (uint16_t stack_index) const
 Returns the function name of the given stack position. More...
 
void output (std::ostream *ptr) const
 Describe this object to the given stream. More...
 
void clear ()
 
ErrorStack to_error_stack () const
 Instantiates an ErrorStack object based on this object. More...
 
void from_error_stack (const ErrorStack &other)
 Convert ErrorStack to this object. More...
 

Friends

std::ostream & operator<< (std::ostream &o, const FixedErrorStack &obj)
 

Member Typedef Documentation

Constructor & Destructor Documentation

foedus::FixedErrorStack::FixedErrorStack ( )
inline

Empty constructor.

Definition at line 48 of file fixed_error_stack.hpp.

48 : os_errno_(0), error_code_(kErrorCodeOk), stack_depth_(0) {}
0 means no-error.
Definition: error_code.hpp:87
foedus::FixedErrorStack::FixedErrorStack ( const ErrorStack src)
inlineexplicit

Copy the content of the given ErrorStack.

Definition at line 50 of file fixed_error_stack.hpp.

References operator=().

50 { operator=(src); }
FixedErrorStack & operator=(const ErrorStack &src)
Assignment operator.

Here is the call graph for this function:

Member Function Documentation

void foedus::FixedErrorStack::clear ( )
inline

Definition at line 91 of file fixed_error_stack.hpp.

References foedus::kErrorCodeOk.

Referenced by from_error_stack(), and foedus::thread::ThreadControlBlock::initialize().

91 { error_code_ = kErrorCodeOk; }
0 means no-error.
Definition: error_code.hpp:87

Here is the caller graph for this function:

void foedus::FixedErrorStack::from_error_stack ( const ErrorStack other)

Convert ErrorStack to this object.

Opposite of to_error_stack

Definition at line 85 of file fixed_error_stack.cpp.

References clear(), foedus::assorted::FixedString< MAXLEN, CHAR >::clear(), foedus::ErrorStack::get_custom_message(), foedus::ErrorStack::get_error_code(), foedus::ErrorStack::get_filename(), foedus::ErrorStack::get_func(), foedus::ErrorStack::get_linenum(), foedus::ErrorStack::get_os_errno(), foedus::ErrorStack::get_stack_depth(), and foedus::ErrorStack::is_error().

85  {
86  if (!other.is_error()) {
87  clear();
88  return;
89  }
90 
91  error_code_ = other.get_error_code();
92  os_errno_ = other.get_os_errno();
93  stack_depth_ = other.get_stack_depth();
94  custom_message_.clear();
95  if (other.get_custom_message()) {
96  custom_message_ = other.get_custom_message();
97  }
98  for (uint16_t i = 0; i < stack_depth_; ++i) {
99  filenames_[i] = other.get_filename(i);
100  funcs_[i] = other.get_func(i);
101  linenums_[i] = other.get_linenum(i);
102  }
103 }
void clear() noexcept
Clear string.

Here is the call graph for this function:

const FixedErrorMessage& foedus::FixedErrorStack::get_custom_message ( ) const
inline

Returns the custom error message.

Definition at line 65 of file fixed_error_stack.hpp.

Referenced by output().

65 { return custom_message_; }

Here is the caller graph for this function:

ErrorCode foedus::FixedErrorStack::get_error_code ( ) const
inline

Return the integer error code.

Definition at line 59 of file fixed_error_stack.hpp.

59 { return error_code_; }
const FixedFileName& foedus::FixedErrorStack::get_filename ( uint16_t  stack_index) const
inline

Returns the file name of the given stack position.

Definition at line 77 of file fixed_error_stack.hpp.

References ASSERT_ND.

Referenced by output().

77  {
78  ASSERT_ND(stack_index < stack_depth_);
79  return filenames_[stack_index];
80  }
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72

Here is the caller graph for this function:

const FixedFuncName& foedus::FixedErrorStack::get_func ( uint16_t  stack_index) const
inline

Returns the function name of the given stack position.

Definition at line 83 of file fixed_error_stack.hpp.

References ASSERT_ND.

Referenced by output().

83  {
84  ASSERT_ND(stack_index < stack_depth_);
85  return funcs_[stack_index];
86  }
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72

Here is the caller graph for this function:

uint32_t foedus::FixedErrorStack::get_linenum ( uint16_t  stack_index) const
inline

Returns the line number of the given stack position.

Definition at line 71 of file fixed_error_stack.hpp.

References ASSERT_ND.

Referenced by output().

71  {
72  ASSERT_ND(stack_index < stack_depth_);
73  return linenums_[stack_index];
74  }
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72

Here is the caller graph for this function:

const char* foedus::FixedErrorStack::get_message ( ) const
inline

Returns the error message inferred by the error code.

Definition at line 62 of file fixed_error_stack.hpp.

References foedus::get_error_message().

Referenced by output().

62 { return get_error_message(error_code_); }
const char * get_error_message(ErrorCode code)
Returns the error messages corresponding to ErrorCode enum defined in error_code.xmacro.
Definition: error_code.hpp:120

Here is the call graph for this function:

Here is the caller graph for this function:

uint16_t foedus::FixedErrorStack::get_stack_depth ( ) const
inline

Returns the depth of stack this error code has collected.

Definition at line 68 of file fixed_error_stack.hpp.

Referenced by output().

68 { return stack_depth_; }

Here is the caller graph for this function:

bool foedus::FixedErrorStack::is_error ( ) const
inline

Returns if this return code is not kErrorCodeOk.

Definition at line 56 of file fixed_error_stack.hpp.

References foedus::kErrorCodeOk.

Referenced by output(), and to_error_stack().

56 { return error_code_ != kErrorCodeOk; }
0 means no-error.
Definition: error_code.hpp:87

Here is the caller graph for this function:

FixedErrorStack & foedus::FixedErrorStack::operator= ( const ErrorStack src)

Assignment operator.

Definition at line 27 of file fixed_error_stack.cpp.

References foedus::assorted::FixedString< MAXLEN, CHAR >::assign(), foedus::assorted::FixedString< MAXLEN, CHAR >::clear(), foedus::ErrorStack::get_custom_message(), foedus::ErrorStack::get_error_code(), foedus::ErrorStack::get_filename(), foedus::ErrorStack::get_func(), foedus::ErrorStack::get_linenum(), foedus::ErrorStack::get_os_errno(), foedus::ErrorStack::get_stack_depth(), foedus::ErrorStack::is_error(), and foedus::kErrorCodeOk.

Referenced by FixedErrorStack().

27  {
28  os_errno_ = 0;
29  error_code_ = kErrorCodeOk;
30  stack_depth_ = 0;
31  custom_message_.clear();
32  if (!src.is_error()) {
33  return *this;
34  }
35 
36  if (src.get_custom_message()) {
37  custom_message_.assign(src.get_custom_message());
38  }
39  stack_depth_ = src.get_stack_depth();
40  for (uint16_t i = 0; i < stack_depth_; ++i) {
41  filenames_[i].assign(src.get_filename(i));
42  funcs_[i].assign(src.get_func(i));
43  linenums_[i] = src.get_linenum(i);
44  }
45  os_errno_ = src.get_os_errno();
46  error_code_ = src.get_error_code();
47  return *this;
48 }
0 means no-error.
Definition: error_code.hpp:87
void assign(const FixedString< MAXLEN2, CHAR > &other) noexcept
Assign operator for all FixedString objects.
void clear() noexcept
Clear string.

Here is the call graph for this function:

Here is the caller graph for this function:

void foedus::FixedErrorStack::output ( std::ostream *  ptr) const

Describe this object to the given stream.

Definition at line 50 of file fixed_error_stack.cpp.

References get_custom_message(), foedus::get_error_name(), get_filename(), get_func(), get_linenum(), get_message(), get_stack_depth(), is_error(), foedus::ErrorStack::kMaxStackDepth, and foedus::assorted::os_error().

Referenced by foedus::operator<<(), and to_error_stack().

50  {
51  std::ostream &o = *ptr; // just to workaround non-const reference rule.
52  if (!is_error()) {
53  o << "No error";
54  } else {
55  o << get_error_name(error_code_) << "(" << error_code_ << "):" << get_message();
56  if (os_errno_ != 0) {
57  o << " (Latest system call error=" << assorted::os_error(os_errno_) << ")";
58  }
59  if (!get_custom_message().empty()) {
60  o << " (Additional message=" << get_custom_message() << ")";
61  }
62 
63  for (uint16_t stack_index = 0; stack_index < get_stack_depth(); ++stack_index) {
64  o << std::endl << " " << get_filename(stack_index)
65  << ":" << get_linenum(stack_index) << ": ";
66  if (!get_func(stack_index).empty()) {
67  o << get_func(stack_index) << "()";
68  }
69  }
71  o << std::endl << " .. and more. Increase kMaxStackDepth to see full stacktraces";
72  }
73  }
74 }
const FixedFuncName & get_func(uint16_t stack_index) const
Returns the function name of the given stack position.
uint16_t get_stack_depth() const
Returns the depth of stack this error code has collected.
const char * get_error_name(ErrorCode code)
Returns the names of ErrorCode enum defined in error_code.xmacro.
Definition: error_code.hpp:108
bool is_error() const
Returns if this return code is not kErrorCodeOk.
Maximum stack trace depth.
Definition: error_stack.hpp:86
const char * get_message() const
Returns the error message inferred by the error code.
std::string os_error()
Thread-safe strerror(errno).
const FixedFileName & get_filename(uint16_t stack_index) const
Returns the file name of the given stack position.
uint32_t get_linenum(uint16_t stack_index) const
Returns the line number of the given stack position.
const FixedErrorMessage & get_custom_message() const
Returns the custom error message.

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::FixedErrorStack::to_error_stack ( ) const

Instantiates an ErrorStack object based on this object.

We can't generate a completely same object (ErrorStack needs const char* pointers), so we put much of information as custom error message.

Definition at line 76 of file fixed_error_stack.cpp.

References ERROR_STACK_MSG, is_error(), foedus::kRetOk, and output().

Referenced by foedus::thread::ImpersonateSession::get_result().

76  {
77  if (!is_error()) {
78  return kRetOk;
79  }
80  std::stringstream msg;
81  output(&msg);
82  return ERROR_STACK_MSG(error_code_, msg.str().c_str());
83 }
bool is_error() const
Returns if this return code is not kErrorCodeOk.
void output(std::ostream *ptr) const
Describe this object to the given stream.
const ErrorStack kRetOk
Normal return value for no-error case.
#define ERROR_STACK_MSG(e, m)
Overload of ERROR_STACK(e) to receive a custom error message.

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o,
const FixedErrorStack obj 
)
friend

Definition at line 106 of file fixed_error_stack.cpp.

106  {
107  obj.output(&o);
108  return o;
109 }

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