Skip to content

Commit

Permalink
Save error on the context before returning error code in vfs_open (#4347
Browse files Browse the repository at this point in the history
)

Save error on the context before returning error code in `tiledb_vfs_open`.

---
TYPE: BUG
DESC: Save error on the context before returning error code in vfs_open

(cherry picked from commit ea25897)
  • Loading branch information
robertbindar authored and ihnorton committed Sep 12, 2023
1 parent 323c99c commit 680e59c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion test/src/unit-capi-vfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void VFSFx::check_vfs(const std::string& path) {
rc = tiledb_vfs_is_file(ctx_, vfs_, foo_file.c_str(), &is_file);
REQUIRE(rc == TILEDB_OK);
REQUIRE(!is_file);
tiledb_vfs_fh_t* fh;
tiledb_vfs_fh_t* fh = nullptr;
rc = tiledb_vfs_open(ctx_, vfs_, foo_file.c_str(), TILEDB_VFS_READ, &fh);
REQUIRE(rc == TILEDB_ERR);
REQUIRE(fh == nullptr);
Expand Down
17 changes: 17 additions & 0 deletions tiledb/api/c_api/vfs/test/unit_capi_vfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -658,3 +658,20 @@ TEST_CASE("C API: tiledb_vfs_fh_is_closed argument validation", "[capi][vfs]") {
TEST_CASE("C API: tiledb_vfs_fh_free argument validation", "[capi][vfs]") {
REQUIRE_NOTHROW(tiledb_vfs_fh_free(nullptr));
}

TEST_CASE(
"C API: tiledb_vfs_open reports error when open fails", "[capi][vfs]") {
ordinary_vfs x;
tiledb_vfs_fh_handle_t* vfs_fh;

tiledb_error_t* error = nullptr;

capi_return_t rc = tiledb_vfs_open(
x.ctx, x.vfs, "doesnotexistfile", TILEDB_VFS_READ, &vfs_fh);
REQUIRE(tiledb_status(rc) == TILEDB_ERR);

rc = tiledb_ctx_get_last_error(x.ctx, &error);
REQUIRE(tiledb_status(rc) == TILEDB_OK);

CHECK(error != nullptr);
}
9 changes: 2 additions & 7 deletions tiledb/api/c_api/vfs/vfs_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,9 @@ capi_return_t tiledb_vfs_open(
throw CAPIStatusException(std::string("Invalid TileDB object: ") + "uri");
}
auto vfs_mode = static_cast<tiledb::sm::VFSMode>(mode);
*fh = tiledb_vfs_fh_t::make_handle(fh_uri, vfs->vfs(), vfs_mode);

// Open VFS file
auto st{(*fh)->open()};
if (!st.ok()) {
tiledb_vfs_fh_t::break_handle(*fh);
return TILEDB_ERR;
}
// Throws if opening the uri is unsuccessful
*fh = tiledb_vfs_fh_t::make_handle(fh_uri, vfs->vfs(), vfs_mode);

return TILEDB_OK;
}
Expand Down
1 change: 1 addition & 0 deletions tiledb/api/c_api/vfs/vfs_api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ struct tiledb_vfs_fh_handle_t
tiledb::sm::VFS* vfs,
tiledb::sm::VFSMode mode)
: vfs_fh_{uri, vfs, mode} {
throw_if_not_ok(vfs_fh_.open());
}

Status open() {
Expand Down

0 comments on commit 680e59c

Please sign in to comment.