Skip to content

Commit aaf82b3

Browse files
Open root group in try catch to produce expected error message
1 parent 42cec76 commit aaf82b3

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

libtiledbvcf/src/dataset/tiledbvcfdataset.cc

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,11 +1097,19 @@ std::unique_ptr<tiledb::Array> TileDBVCFDataset::open_vcf_array(
10971097

10981098
// Until 0.38.1 `vcf_headers` array was registered under the root group.
10991099
// Now it is registered under `metadata` group in which physically exist.
1100-
Group root_group(*ctx_, root_uri_, TILEDB_READ);
1100+
std::unique_ptr<tiledb::Group> root_group;
1101+
try {
1102+
root_group = std::make_unique<tiledb::Group>(*ctx_, root_uri_, TILEDB_READ);
1103+
} catch (const tiledb::TileDBError& ex) {
1104+
throw std::runtime_error(
1105+
"Cannot open TileDB-VCF dataset; dataset '" + root_uri_ +
1106+
"' or its metadata does not exist. TileDB error message: " +
1107+
std::string(ex.what()));
1108+
}
11011109

11021110
// We are opening a legacy dataset where the `vcf_headers` array is
11031111
// registered under the root group
1104-
if (utils::has_member(root_group, VCF_HEADER_ARRAY)) {
1112+
if (utils::has_member(*root_group, VCF_HEADER_ARRAY)) {
11051113
if (utils::detect_tiledb_data_protocol(root_uri_, *ctx_) ==
11061114
utils::TileDBDataProtocol::TILEDBV3) {
11071115
// This is an legacy dataset registered under TileDB Carrara
@@ -1118,22 +1126,22 @@ std::unique_ptr<tiledb::Array> TileDBVCFDataset::open_vcf_array(
11181126
VCF_HEADER_ARRAY,
11191127
vcf_headers_uri(root_uri_),
11201128
vcf_headers_uri(root_uri_, false, true));
1121-
} else {
1129+
} else if (utils::has_member(*root_group, METADATA_GROUP)) {
11221130
// Load the `metadata` group
11231131
std::string metadata_uri;
11241132

11251133
// If the group member uri is a cloud uri and the root uri is not,
11261134
// use the non cloud uri instead of the group member uri
11271135
if (!cloud_dataset(root_uri_) &&
1128-
cloud_dataset(root_group.member(METADATA_GROUP).uri())) {
1136+
cloud_dataset(root_group->member(METADATA_GROUP).uri())) {
11291137
metadata_uri = metadata_group_uri(root_uri_);
11301138
LOG_DEBUG(
11311139
"Override group uri '{}'. Open '{}' using uri path '{}'",
1132-
root_group.member(METADATA_GROUP).uri(),
1140+
root_group->member(METADATA_GROUP).uri(),
11331141
METADATA_GROUP,
11341142
metadata_uri);
11351143
} else {
1136-
metadata_uri = root_group.member(METADATA_GROUP).uri();
1144+
metadata_uri = root_group->member(METADATA_GROUP).uri();
11371145
LOG_DEBUG("Open '{}' using group uri '{}'", METADATA_GROUP, metadata_uri);
11381146
}
11391147

@@ -1153,6 +1161,9 @@ std::unique_ptr<tiledb::Array> TileDBVCFDataset::open_vcf_array(
11531161
array_uri = metadata_group.member(VCF_HEADER_ARRAY).uri();
11541162
LOG_DEBUG("Open '{}' using array uri '{}'", VCF_HEADER_ARRAY, array_uri);
11551163
}
1164+
} else {
1165+
// The group seems to have to member added. Fallback to absolute path
1166+
array_uri = vcf_headers_uri(root_uri_);
11561167
}
11571168

11581169
try {

libtiledbvcf/src/utils/utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,13 @@ bool query_buffers_set(tiledb::Query* query);
495495
*/
496496
std::string temp_filename(const std::string& extension = "");
497497

498+
/**
499+
* @brief Check if a member with the given name exists in a group.
500+
*
501+
* @param group The group to to check
502+
* @param member The member name to check for existence
503+
* @return True if there is a member with the given name, false otherwise
504+
*/
498505
bool has_member(const tiledb::Group& group, const std::string& member);
499506

500507
} // namespace utils

0 commit comments

Comments
 (0)