diff --git a/src/delta_utils.cpp b/src/delta_utils.cpp index 1973d2d..b02e898 100644 --- a/src/delta_utils.cpp +++ b/src/delta_utils.cpp @@ -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; @@ -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); } diff --git a/src/include/delta_utils.hpp b/src/include/delta_utils.hpp index 12db332..bcb5f74 100644 --- a/src/include/delta_utils.hpp +++ b/src/include/delta_utils.hpp @@ -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); @@ -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.