Skip to content

Commit

Permalink
solve linker error with refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
samansmink committed May 30, 2024
1 parent 0a52d23 commit ecf865f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
45 changes: 44 additions & 1 deletion src/delta_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,49 @@ ffi::EngineError* DuckDBEngineError::AllocateError(ffi::KernelError etype, ffi::
return error;
}

string DuckDBEngineError::KernelErrorEnumToString(ffi::KernelError err) {
const char* KERNEL_ERROR_ENUM_STRINGS[] = {
"UnknownError",
"FFIError",
"ArrowError",
"EngineDataTypeError",
"ExtractError",
"GenericError",
"IOErrorError",
"ParquetError",
"ObjectStoreError",
"ObjectStorePathError",
"Reqwest",
"FileNotFoundError",
"MissingColumnError",
"UnexpectedColumnTypeError",
"MissingDataError",
"MissingVersionError",
"DeletionVectorError",
"InvalidUrlError",
"MalformedJsonError",
"MissingMetadataError",
"MissingProtocolError",
"MissingMetadataAndProtocolError",
"ParseError",
"JoinFailureError",
"Utf8Error",
"ParseIntError",
"InvalidColumnMappingMode",
"InvalidTableLocation",
"InvalidDecimalError",
};

static_assert(sizeof(KERNEL_ERROR_ENUM_STRINGS)/sizeof(char*)-1 == (int)ffi::KernelError::InvalidDecimalError,
"KernelErrorEnumStrings mismatched with kernel");

if ((int)err < sizeof(KERNEL_ERROR_ENUM_STRINGS)/sizeof(char*)) {
return KERNEL_ERROR_ENUM_STRINGS[(int)err];
}

return StringUtil::Format("EnumOutOfRange (enum val out of range: %d)", (int)err);
}

void DuckDBEngineError::Throw(string from_where) {
// Make copies before calling delete this
auto etype_copy = etype;
Expand All @@ -107,7 +150,7 @@ void DuckDBEngineError::Throw(string from_where) {
// Consume error by calling delete this (remember this error is created by kernel using AllocateError)
delete this;
throw IOException("Hit DeltaKernel FFI error (from: %s): Hit error: %u (%s) with message (%s)",
from_where.c_str(), etype_copy, KERNEL_ERROR_ENUM_STRINGS[(int)etype_copy], message_copy);
from_where.c_str(), etype_copy, KernelErrorEnumToString(etype_copy), message_copy);
}


Expand Down
37 changes: 2 additions & 35 deletions src/include/delta_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,38 +45,10 @@ class SchemaVisitor {

// Allocator for errors that the kernel might throw
struct DuckDBEngineError : ffi::EngineError {
// Different Kernel errors
static constexpr char* KERNEL_ERROR_ENUM_STRINGS[] = {
"UnknownError",
"FFIError",
"ArrowError",
"EngineDataTypeError",
"ExtractError",
"GenericError",
"IOErrorError",
"ParquetError",
"ObjectStoreError",
"ObjectStorePathError",
"Reqwest",
"FileNotFoundError",
"MissingColumnError",
"UnexpectedColumnTypeError",
"MissingDataError",
"MissingVersionError",
"DeletionVectorError",
"InvalidUrlError",
"MalformedJsonError",
"MissingMetadataError",
"MissingProtocolError",
"MissingMetadataAndProtocolError",
"ParseError",
"JoinFailureError",
"Utf8Error",
"ParseIntError"
};

// Allocate a DuckDBEngineError, function ptr passed to kernel for error allocation
static ffi::EngineError* AllocateError(ffi::KernelError etype, ffi::KernelStringSlice msg);
// Convert a kernel error enum to a string
static string KernelErrorEnumToString(ffi::KernelError err);

// Throw the error as an IOException
[[noreturn]] void Throw(string from_info);
Expand All @@ -85,11 +57,6 @@ struct DuckDBEngineError : ffi::EngineError {
string error_message;
};

static_assert(sizeof(DuckDBEngineError::KERNEL_ERROR_ENUM_STRINGS)/sizeof(char*)-1 == (int)ffi::KernelError::ParseIntError,
"KernelErrorEnumStrings failin");



// RAII wrapper that returns ownership of a kernel pointer to kernel when it goes out of
// scope. Similar to std::unique_ptr. but does not define operator->() and does not require the
// kernel type to be complete.
Expand Down

0 comments on commit ecf865f

Please sign in to comment.