Skip to content

Commit 8599690

Browse files
committed
Add Error Checking to FileHandle
1 parent cb05c31 commit 8599690

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

tiledb/cc/vfs.cc

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,25 @@ void init_vfs(py::module &m) {
4646

4747
class FileHandle {
4848
private:
49-
tiledb_ctx_t *_ctx;
49+
Context _ctx;
5050
tiledb_vfs_fh_t *_fh;
5151

5252
public:
53-
// TODO ERROR CHECKING
54-
5553
FileHandle(const Context &ctx, const VFS &vfs, std::string uri,
5654
tiledb_vfs_mode_t mode)
57-
: _ctx(ctx.ptr().get()) {
58-
tiledb_vfs_open(this->_ctx, vfs.ptr().get(), uri.c_str(), mode, &this->_fh);
55+
: _ctx(ctx) {
56+
_ctx.handle_error(tiledb_vfs_open(_ctx.ptr().get(), vfs.ptr().get(),
57+
uri.c_str(), mode, &this->_fh));
5958
}
6059

61-
void close() { tiledb_vfs_close(this->_ctx, this->_fh); }
60+
void close() { tiledb_vfs_close(_ctx.ptr().get(), this->_fh); }
6261

6362
py::bytes read(uint64_t offset, uint64_t nbytes) {
6463
py::array data = py::array(py::dtype::of<std::byte>(), nbytes);
6564
py::buffer_info buffer = data.request();
66-
tiledb_vfs_read(this->_ctx, this->_fh, offset, buffer.ptr, nbytes);
65+
66+
_ctx.handle_error(tiledb_vfs_read(_ctx.ptr().get(), this->_fh, offset,
67+
buffer.ptr, nbytes));
6768

6869
auto np = py::module::import("numpy");
6970
auto to_bytes = np.attr("ndarray").attr("tobytes");
@@ -73,14 +74,18 @@ class FileHandle {
7374

7475
void write(py::buffer data) {
7576
py::buffer_info buffer = data.request();
76-
tiledb_vfs_write(this->_ctx, this->_fh, buffer.ptr, buffer.shape[0]);
77+
_ctx.handle_error(tiledb_vfs_write(_ctx.ptr().get(), this->_fh, buffer.ptr,
78+
buffer.shape[0]));
7779
}
7880

79-
void flush() { tiledb_vfs_sync(this->_ctx, this->_fh); }
81+
void flush() {
82+
_ctx.handle_error(tiledb_vfs_sync(_ctx.ptr().get(), this->_fh));
83+
}
8084

8185
bool closed() {
8286
int32_t is_closed;
83-
tiledb_vfs_fh_is_closed(this->_ctx, this->_fh, &is_closed);
87+
_ctx.handle_error(
88+
tiledb_vfs_fh_is_closed(_ctx.ptr().get(), this->_fh, &is_closed));
8489
return is_closed;
8590
}
8691
};

0 commit comments

Comments
 (0)