Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::ErrorData Class Reference
Collaboration diagram for duckdb::ErrorData:

Public Member Functions

DUCKDB_API ErrorData ()
 Not initialized, default constructor.
 
DUCKDB_API ErrorData (const std::exception &ex)
 From std::exception.
 
DUCKDB_API ErrorData (ExceptionType type, const string &raw_message)
 From a raw string and exception type.
 
DUCKDB_API ErrorData (const string &raw_message)
 From a raw string.
 
DUCKDB_API void Throw (const string &prepended_message="") const
 Throw the error.
 
DUCKDB_API const ExceptionType & Type () const
 Get the internal exception type of the error.
 
DUCKDB_API const string & Message () const
 Used in clients like C-API, creates the final message and returns a reference to it.
 
DUCKDB_API const string & RawMessage () const
 
DUCKDB_API void Merge (const ErrorData &other)
 
DUCKDB_API bool operator== (const ErrorData &other) const
 
bool HasError () const
 Returns true, if this error data contains an exception, else false.
 
const unordered_map< string, string > & ExtraInfo () const
 
DUCKDB_API void FinalizeError ()
 
DUCKDB_API void AddErrorLocation (const string &query)
 
DUCKDB_API void ConvertErrorToJSON ()
 
DUCKDB_API void AddQueryLocation (optional_idx query_location)
 
DUCKDB_API void AddQueryLocation (QueryErrorContext error_context)
 
DUCKDB_API void AddQueryLocation (const ParsedExpression &ref)
 
DUCKDB_API void AddQueryLocation (const TableRef &ref)
 

Private Member Functions

DUCKDB_API string ConstructFinalMessage () const
 

Static Private Member Functions

static DUCKDB_API string SanitizeErrorMessage (string error)
 

Private Attributes

bool initialized
 Whether this ErrorData contains an exception or not.
 
ExceptionType type
 The ExceptionType of the preserved exception.
 
string raw_message
 The message the exception was constructed with (does not contain the Exception Type)
 
string final_message
 The final message (stored in the preserved error for compatibility reasons with C-API)
 
unordered_map< string, string > extra_info
 Extra exception info.
 

Constructor & Destructor Documentation

◆ ErrorData() [1/4]

duckdb::ErrorData::ErrorData ( )

Not initialized, default constructor.

70131 : initialized(false), type(ExceptionType::INVALID) {
70132}
ExceptionType type
The ExceptionType of the preserved exception.
Definition duckdb.hpp:6547
bool initialized
Whether this ErrorData contains an exception or not.
Definition duckdb.hpp:6545

◆ ErrorData() [2/4]

duckdb::ErrorData::ErrorData ( const std::exception &  ex)

From std::exception.

70134 : ErrorData(ex.what()) {
70135}
DUCKDB_API ErrorData()
Not initialized, default constructor.
Definition duckdb.cpp:70131

◆ ErrorData() [3/4]

duckdb::ErrorData::ErrorData ( ExceptionType  type,
const string &  raw_message 
)

From a raw string and exception type.

70138 : initialized(true), type(type), raw_message(SanitizeErrorMessage(message)) {
70139 // In the case of ExceptionType::INTERNAL, the stack trace is part of the final message.
70140 // To construct it, we need to access extra_info, which has to be initialized first.
70141 // Thus, we only set final_message in the constructor's body.
70142 final_message = ConstructFinalMessage();
70143}
string raw_message
The message the exception was constructed with (does not contain the Exception Type)
Definition duckdb.hpp:6549
string final_message
The final message (stored in the preserved error for compatibility reasons with C-API)
Definition duckdb.hpp:6551

◆ ErrorData() [4/4]

duckdb::ErrorData::ErrorData ( const string &  raw_message)
explicit

From a raw string.

70146 : initialized(true), type(ExceptionType::INVALID), raw_message(string()), final_message(string()) {
70147 // parse the constructed JSON
70148 if (message.empty() || message[0] != '{') {
70149 // Not a JSON-formatted message.
70150 // Use the message as a raw Exception message and leave the type as uninitialized.
70151 if (message == std::bad_alloc().what()) {
70152 type = ExceptionType::OUT_OF_MEMORY;
70153 raw_message = "Allocation failure";
70154 } else {
70155 raw_message = message;
70156 }
70157 final_message = ConstructFinalMessage();
70158 return;
70159 }
70160
70161 // JSON-formatted message.
70162 auto info = StringUtil::ParseJSONMap(message)->Flatten();
70163 for (auto &entry : info) {
70164 if (entry.first == "exception_type") {
70165 type = Exception::StringToExceptionType(entry.second);
70166 } else if (entry.first == "exception_message") {
70167 raw_message = SanitizeErrorMessage(entry.second);
70168 } else {
70169 extra_info[entry.first] = entry.second;
70170 }
70171 }
70172 final_message = ConstructFinalMessage();
70173}
unordered_map< string, string > extra_info
Extra exception info.
Definition duckdb.hpp:6553
static DUCKDB_API unique_ptr< ComplexJSON > ParseJSONMap(const string &json, bool ignore_errors=false)
Here is the call graph for this function:

Member Function Documentation

◆ Throw()

void duckdb::ErrorData::Throw ( const string &  prepended_message = "") const

Throw the error.

70200 {
70201 D_ASSERT(initialized);
70202 if (!prepended_message.empty()) {
70203 string new_message = prepended_message + raw_message;
70204 throw Exception(extra_info, type, new_message);
70205 }
70206 throw Exception(extra_info, type, raw_message);
70207}

◆ Type()

const ExceptionType & duckdb::ErrorData::Type ( ) const

Get the internal exception type of the error.

70209 {
70210 D_ASSERT(initialized);
70211 return this->type;
70212}

◆ Message()

DUCKDB_API const string & duckdb::ErrorData::Message ( ) const
inline

Used in clients like C-API, creates the final message and returns a reference to it.

6517 {
6518 return final_message;
6519 }

◆ RawMessage()

DUCKDB_API const string & duckdb::ErrorData::RawMessage ( ) const
inline
6520 {
6521 return raw_message;
6522 }

◆ Merge()

void duckdb::ErrorData::Merge ( const ErrorData other)
70214 {
70215 if (!other.HasError()) {
70216 return;
70217 }
70218 if (!HasError()) {
70219 *this = other;
70220 return;
70221 }
70222 if (Exception::InvalidatesDatabase(other.Type()) || other.type == ExceptionType::INTERNAL) {
70223 // inherit severe types
70224 type = other.type;
70225 }
70226 final_message += "\n\n" + other.Message();
70227}
bool HasError() const
Returns true, if this error data contains an exception, else false.
Definition duckdb.hpp:6527

◆ operator==()

bool duckdb::ErrorData::operator== ( const ErrorData other) const
70229 {
70230 if (initialized != other.initialized) {
70231 return false;
70232 }
70233 if (type != other.type) {
70234 return false;
70235 }
70236 return raw_message == other.raw_message;
70237}

◆ HasError()

bool duckdb::ErrorData::HasError ( ) const
inline

Returns true, if this error data contains an exception, else false.

6527 {
6528 return initialized;
6529 }

◆ ExtraInfo()

const unordered_map< string, string > & duckdb::ErrorData::ExtraInfo ( ) const
inline
6530 {
6531 return extra_info;
6532 }

◆ FinalizeError()

void duckdb::ErrorData::FinalizeError ( )
70248 {
70249 auto entry = extra_info.find("stack_trace_pointers");
70250 if (entry != extra_info.end()) {
70251 auto stack_trace = StackTrace::ResolveStacktraceSymbols(entry->second);
70252 extra_info["stack_trace"] = std::move(stack_trace);
70253 extra_info.erase("stack_trace_pointers");
70254 }
70255}

◆ AddErrorLocation()

void duckdb::ErrorData::AddErrorLocation ( const string &  query)
70257 {
70258 if (!query.empty()) {
70259 auto entry = extra_info.find("position");
70260 if (entry != extra_info.end()) {
70261 raw_message = QueryErrorContext::Format(query, raw_message, std::stoull(entry->second));
70262 extra_info.erase(entry);
70263 }
70264 }
70265 {
70266 auto entry = extra_info.find("stack_trace");
70267 if (entry != extra_info.end() && !entry->second.empty()) {
70268 raw_message += "\n\nStack Trace:\n" + entry->second;
70269 entry->second = "";
70270 }
70271 }
70272 final_message = ConstructFinalMessage();
70273}

◆ ConvertErrorToJSON()

void duckdb::ErrorData::ConvertErrorToJSON ( )
70239 {
70240 if (!raw_message.empty() && raw_message[0] == '{') {
70241 // empty or already JSON
70242 return;
70243 }
70246}
static DUCKDB_API string ExceptionToJSONMap(ExceptionType type, const string &message, const unordered_map< string, string > &map)

◆ AddQueryLocation() [1/4]

void duckdb::ErrorData::AddQueryLocation ( optional_idx  query_location)
70275 {
70276 Exception::SetQueryLocation(query_location, extra_info);
70277}

◆ AddQueryLocation() [2/4]

void duckdb::ErrorData::AddQueryLocation ( QueryErrorContext  error_context)
70279 {
70280 AddQueryLocation(error_context.query_location);
70281}

◆ AddQueryLocation() [3/4]

void duckdb::ErrorData::AddQueryLocation ( const ParsedExpression ref)
70283 {
70284 AddQueryLocation(ref.GetQueryLocation());
70285}

◆ AddQueryLocation() [4/4]

void duckdb::ErrorData::AddQueryLocation ( const TableRef ref)
70287 {
70288 AddQueryLocation(ref.query_location);
70289}

◆ SanitizeErrorMessage()

string duckdb::ErrorData::SanitizeErrorMessage ( string  error)
staticprivate
70175 {
70176 return StringUtil::Replace(std::move(error), string("\0", 1), "\\0");
70177}

◆ ConstructFinalMessage()

string duckdb::ErrorData::ConstructFinalMessage ( ) const
private
70179 {
70180 std::string error;
70181 if (type != ExceptionType::UNKNOWN_TYPE) {
70182 error = Exception::ExceptionTypeToString(type) + " ";
70183 }
70184 error += "Error: " + raw_message;
70185 if (type == ExceptionType::INTERNAL) {
70186 error += "\nThis error signals an assertion failure within DuckDB. This usually occurs due to "
70187 "unexpected conditions or errors in the program's logic.\nFor more information, see "
70188 "https://duckdb.org/docs/stable/dev/internal_errors";
70189
70190 // Ensure that we print the stack trace for internal and fatal exceptions.
70191 auto entry = extra_info.find("stack_trace_pointers");
70192 if (entry != extra_info.end()) {
70193 auto stack_trace = StackTrace::ResolveStacktraceSymbols(entry->second);
70194 error += "\n\nStack Trace:\n" + stack_trace;
70195 }
70196 }
70197 return error;
70198}
void error(int _code, const String &_err, const char *_func, const char *_file, int _line)

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