Skip to content

Commit

Permalink
throw exception when file not existing
Browse files Browse the repository at this point in the history
  • Loading branch information
Zilong-Li committed Aug 6, 2024
1 parent ae06697 commit 369c4b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tools/vcf2beagle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main(int argc, char * argv[])
vector<double> out;
while(vcf.getNextVariant(var))
{
if(!var.isSNP()) continue;
// if(!var.isSNP()) continue;
if(tag == "PL")
{
var.getFORMAT("PL", pl); // try get PL values
Expand Down
4 changes: 4 additions & 0 deletions vcfpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,7 @@ class BcfReader
{
fname = file;
fp = std::shared_ptr<htsFile>(hts_open(file.c_str(), "r"), htsFile_close());
if(!fp) throw std::invalid_argument("I/O error: input file is invalid");
header.hdr = bcf_hdr_read(fp.get());
nsamples = bcf_hdr_nsamples(header.hdr);
SamplesName = header.getSamples();
Expand Down Expand Up @@ -1710,6 +1711,7 @@ class BcfWriter
{
auto mode = getMode(fname, "w");
fp = std::shared_ptr<htsFile>(hts_open(fname.c_str(), mode.c_str()), htsFile_close());
if(!fp) throw std::invalid_argument("I/O error: input file is invalid");
}

/**
Expand All @@ -1724,6 +1726,7 @@ class BcfWriter
void open(const std::string & fname, const std::string & mode)
{
fp = std::shared_ptr<htsFile>(hts_open(fname.c_str(), mode.c_str()), htsFile_close());
if(!fp) throw std::invalid_argument("I/O error: input file is invalid");
}

/// close the BcfWriter object.
Expand Down Expand Up @@ -1751,6 +1754,7 @@ class BcfWriter
void copyHeader(const std::string & vcffile)
{
htsFile * fp2 = hts_open(vcffile.c_str(), "r");
if(!fp2) throw std::invalid_argument("I/O error: input file is invalid");
header.hdr = bcf_hdr_read(fp2);
hts_close(fp2);
initalHeader(header);
Expand Down

0 comments on commit 369c4b2

Please sign in to comment.