diff --git a/cpp/Enums.cpp b/cpp/Enums.cpp index 48b30ce0..6f80aaca 100644 --- a/cpp/Enums.cpp +++ b/cpp/Enums.cpp @@ -97,6 +97,10 @@ namespace static_assert(::arrow::TimeUnit::type::MILLI == 1); static_assert(::arrow::TimeUnit::type::MICRO == 2); static_assert(::arrow::TimeUnit::type::NANO == 3); - } + // Arrow StatusCode values that should be kept up to date with ArrowStatusCode.cs + static_assert((int) ::arrow::StatusCode::OutOfMemory == 1); + static_assert((int) ::arrow::StatusCode::IOError == 5); + static_assert((int) ::arrow::StatusCode::UnknownError == 9); + } } \ No newline at end of file diff --git a/cpp/ExceptionInfo.h b/cpp/ExceptionInfo.h index 17fe194f..02b946f9 100644 --- a/cpp/ExceptionInfo.h +++ b/cpp/ExceptionInfo.h @@ -3,6 +3,8 @@ #include #include +#include + struct ExceptionInfo final { ExceptionInfo(const char* type, const char* message); @@ -14,23 +16,28 @@ struct ExceptionInfo final }; #define SINGLE_ARG(...) __VA_ARGS__ -#define TRYCATCH(expression) \ - try \ - { \ - expression \ - return nullptr; \ - } \ - catch (const std::bad_alloc& exception) \ - { \ - return new ExceptionInfo("OutOfMemoryException", exception.what()); \ - } \ - catch (const std::exception& exception) \ - { \ - return new ExceptionInfo(exception); \ - } \ - catch (...) \ - { \ - return new ExceptionInfo("unkown", "uncaught exception"); \ - } \ - +#define TRYCATCH(expression) \ + try \ + { \ + expression \ + return nullptr; \ + } \ + catch (const std::bad_alloc& exception) \ + { \ + return new ExceptionInfo("OutOfMemoryException", exception.what()); \ + } \ + catch (const parquet::ParquetStatusException& exception) \ + { \ + return exception.status().IsOutOfMemory() \ + ? new ExceptionInfo("OutOfMemoryException", exception.what()) \ + : new ExceptionInfo(exception); \ + } \ + catch (const std::exception& exception) \ + { \ + return new ExceptionInfo(exception); \ + } \ + catch (...) \ + { \ + return new ExceptionInfo("unknown", "uncaught exception"); \ + } \ diff --git a/cpp/ManagedRandomAccessFile.cpp b/cpp/ManagedRandomAccessFile.cpp index 536e48af..2a6beae6 100644 --- a/cpp/ManagedRandomAccessFile.cpp +++ b/cpp/ManagedRandomAccessFile.cpp @@ -121,7 +121,7 @@ class ManagedRandomAccessFile final : public arrow::io::RandomAccessFile return Result(result); } - return Result(Status(statusCode, exception)); + return Result(Status(statusCode, exception == nullptr ? "" : exception)); } static Status GetStatus(const StatusCode statusCode, const char* const exception) diff --git a/csharp/ArrowStatusCode.cs b/csharp/ArrowStatusCode.cs new file mode 100644 index 00000000..9be4fddd --- /dev/null +++ b/csharp/ArrowStatusCode.cs @@ -0,0 +1,12 @@ +namespace ParquetSharp +{ + /// + /// Subset of Arrow StatusCode enums used from ParquetSharp. + /// + internal enum ArrowStatusCode + { + OutOfMemory = 1, + IOError = 5, + UnknownError = 9, + } +} diff --git a/csharp/IO/ManagedRandomAccessFile.cs b/csharp/IO/ManagedRandomAccessFile.cs index 3206cf6f..50c10352 100644 --- a/csharp/IO/ManagedRandomAccessFile.cs +++ b/csharp/IO/ManagedRandomAccessFile.cs @@ -168,16 +168,16 @@ private byte HandleException(Exception error, out string? exception) if (error is OutOfMemoryException) { exception = _exceptionMessage = null; - return 1; + return (byte) ArrowStatusCode.OutOfMemory; } if (error is IOException) { exception = _exceptionMessage = error.ToString(); - return 5; + return (byte) ArrowStatusCode.IOError; } exception = _exceptionMessage = error.ToString(); - return 9; + return (byte) ArrowStatusCode.UnknownError; } [DllImport(ParquetDll.Name)] diff --git a/csharp/ParquetSharp.csproj b/csharp/ParquetSharp.csproj index a486ae18..8dff0baf 100644 --- a/csharp/ParquetSharp.csproj +++ b/csharp/ParquetSharp.csproj @@ -12,7 +12,7 @@ true true 1591; - 16.1.0-beta1 + 16.1.0-beta2 G-Research G-Research ParquetSharp