This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-vector-index.git
The following commit(s) were added to refs/heads/main by this push:
new 4e282e6 fix: preserve native open errors in C++ bindings (#117)
4e282e6 is described below
commit 4e282e6a08430b15787d43a08edbbdbc7a3c12a6
Author: Daoyuan Wang <[email protected]>
AuthorDate: Wed Nov 11 16:35:49 2026 +0800
fix: preserve native open errors in C++ bindings (#117)
---
cpp/test_vindex.cpp | 32 ++++++++++++++++++++++++++++++++
include/paimon_vindex.hpp | 11 ++++++++---
2 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/cpp/test_vindex.cpp b/cpp/test_vindex.cpp
index 32fa9bc..308fc91 100644
--- a/cpp/test_vindex.cpp
+++ b/cpp/test_vindex.cpp
@@ -702,7 +702,39 @@ static void test_range_matrix() {
}
}
+static void test_native_open_errors_preserve_details() {
+ const char* keys[] = {"index.type", "dimension", "nlist", "metric"};
+ const char* values[] = {"ivf_flat", "8", "4", "bogus"};
+ for (bool raw_options : {false, true}) {
+ bool rejected = false;
+ try {
+ if (raw_options) {
+ paimon::vindex::Trainer trainer(keys, values, 4);
+ } else {
+ paimon::vindex::Trainer
trainer(std::vector<std::pair<std::string, std::string>>{
+ {"index.type", "ivf_flat"}, {"dimension", "8"},
+ {"nlist", "4"}, {"metric", "bogus"},
+ });
+ }
+ } catch (const paimon::vindex::Error& error) {
+ rejected = std::string(error.what()).find("unknown metric
'bogus'") != std::string::npos;
+ }
+ ASSERT_TRUE(rejected);
+ }
+ bool rejected = false;
+ try {
+ paimon::vindex::InputFile input;
+ input.read_ranges_fn = [](paimon::vindex::ReadRequest*, size_t) {
return -1; };
+ paimon::vindex::Reader reader(std::move(input));
+ } catch (const paimon::vindex::Error& error) {
+ rejected = std::string(error.what()).find("read_ranges callback
failed") != std::string::npos;
+ }
+ ASSERT_TRUE(rejected);
+ printf("PASS native_open_errors_preserve_details\n");
+}
+
int main() {
+ test_native_open_errors_preserve_details();
test_supported_index_roundtrips();
test_worker_callback_reentry_is_rejected();
test_extensible_search_params_forward_query_tuning();
diff --git a/include/paimon_vindex.hpp b/include/paimon_vindex.hpp
index c6e8308..6fedbe5 100644
--- a/include/paimon_vindex.hpp
+++ b/include/paimon_vindex.hpp
@@ -68,6 +68,11 @@ struct InputFile {
namespace detail {
+inline std::string native_error_message(const char* fallback) {
+ const char* error = paimon_vindex_last_error();
+ return error ? std::string(error) : std::string(fallback);
+}
+
class NativeCallbackScope {
public:
explicit NativeCallbackScope(const void* context) noexcept
@@ -407,7 +412,7 @@ class Trainer {
public:
Trainer(const char* const* keys, const char* const* values, size_t
num_options) {
handle_ = paimon_vindex_trainer_open(keys, values, num_options);
- if (!handle_) throw Error("failed to open vector index trainer");
+ if (!handle_) throw Error(detail::native_error_message("failed to open
vector index trainer"));
}
explicit Trainer(const std::vector<std::pair<std::string, std::string>>&
options) {
@@ -424,7 +429,7 @@ public:
value_ptrs_.push_back(option_values_[i].c_str());
}
handle_ = paimon_vindex_trainer_open(key_ptrs_.data(),
value_ptrs_.data(), options.size());
- if (!handle_) throw Error("failed to open vector index trainer");
+ if (!handle_) throw Error(detail::native_error_message("failed to open
vector index trainer"));
}
Trainer(const Trainer&) = delete;
@@ -581,7 +586,7 @@ public:
PaimonVindexReaderOptions options;
options.memory_budget_bytes = memory_budget_bytes;
handle_ = paimon_vindex_reader_open_with_options(raw, options);
- if (!handle_) throw Error("failed to open vector index reader");
+ if (!handle_) throw Error(detail::native_error_message("failed to open
vector index reader"));
}
Reader(const Reader&) = delete;