Skip to content

Commit 2d1886f

Browse files
authored
Retry vcf_open in VCF read header function (#801)
1 parent 0776559 commit 2d1886f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

libtiledbvcf/src/dataset/tiledbvcfdataset.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ std::vector<std::string> TileDBVCFDataset::get_vcf_attributes(std::string uri) {
165165

166166
// Read VCF header into string for parsing
167167
bcf_hdr_t* hdr = VCFUtils::hdr_read_header(uri);
168+
if (hdr == nullptr) {
169+
throw std::runtime_error("Error reading VCF header from: " + uri);
170+
}
168171
std::string hdrstr = VCFUtils::hdr_to_string(hdr);
169172
const char* p = hdrstr.c_str();
170173

libtiledbvcf/src/vcf/vcf_utils.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ uint32_t VCFUtils::get_end_pos(
6262

6363
bcf_hdr_t* VCFUtils::hdr_read_header(const std::string& path) {
6464
auto fh = vcf_open(path.c_str(), "r");
65+
66+
int retries = 3;
67+
while (!fh && retries--) {
68+
fh = vcf_open(path.c_str(), "r");
69+
}
70+
6571
if (!fh)
6672
return nullptr;
6773
auto hdr = bcf_hdr_read(fh);

0 commit comments

Comments
 (0)