Skip to content

Commit 7b31d42

Browse files
committed
check missing input in vg_set
1 parent b2db425 commit 7b31d42

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/vg_set.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,21 @@ int64_t VGset::merge_id_space(void) {
7575
}
7676

7777
void VGset::to_xg(xg::XG& index) {
78+
79+
function<void(const string&, std::ifstream&)> check_stream = [&](const string&name, std::ifstream& in) {
80+
if (name == "-"){
81+
if (!in) throw ifstream::failure("vg_set: cannot read from stdin. Failed to open " + name);
82+
}
83+
84+
if (!in) throw ifstream::failure("failed to open " + name);
85+
};
7886

7987
// We need to recostruct full removed paths from fragmentary paths encountered in each chunk.
8088
// This maps from path name to all the Mappings in the path in the order we encountered them
8189
auto for_each_sequence = [&](const std::function<void(const std::string& seq, const nid_t& node_id)>& lambda) {
8290
for (auto& name : filenames) {
8391
std::ifstream in(name);
92+
check_stream(name, in);
8493
vg::io::for_each(in, (function<void(Graph&)>)[&](Graph& graph) {
8594
for (uint64_t i = 0; i < graph.node_size(); ++i) {
8695
auto& node = graph.node(i);
@@ -93,6 +102,7 @@ void VGset::to_xg(xg::XG& index) {
93102
auto for_each_edge = [&](const std::function<void(const nid_t& from, const bool& from_rev, const nid_t& to, const bool& to_rev)>& lambda) {
94103
for (auto& name : filenames) {
95104
std::ifstream in(name);
105+
check_stream(name, in);
96106
vg::io::for_each(in, (function<void(Graph&)>)[&](Graph& graph) {
97107
for (uint64_t i = 0; i < graph.edge_size(); ++i) {
98108
auto& edge = graph.edge(i);
@@ -107,6 +117,7 @@ void VGset::to_xg(xg::XG& index) {
107117
map<string, vector<pair<nid_t, bool>>> paths;
108118
for (auto& name : filenames) {
109119
std::ifstream in(name);
120+
check_stream(name, in);
110121
vg::io::for_each(in, (function<void(Graph&)>)[&](Graph& graph) {
111122
for (uint64_t i = 0; i < graph.path_size(); ++i) {
112123
auto& path = graph.path(i);

0 commit comments

Comments
 (0)