Skip to content

Commit

Permalink
MRG: fail-exit when 0 signatures are loaded from a collection (#282)
Browse files Browse the repository at this point in the history
Error out when 0 signatures are loaded from a collection. 

Since we currently only load a single collection as our query or database, 0 sigs in either means that no useful results would be obtained.

- Fixes #207
  • Loading branch information
bluegenes authored Mar 20, 2024
1 parent 34adf84 commit 4004e85
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
7 changes: 0 additions & 7 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ pub fn index<P: AsRef<Path>>(
allow_failed_sigpaths,
)?;

if collection.len() == 0 {
bail!(
"No sketches matching parameters, check input: '{}'",
&siglist
)
}

RevIndex::create(
output.as_ref(),
collection.select(selection)?.try_into()?,
Expand Down
3 changes: 2 additions & 1 deletion src/python/tests/test_multigather.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,8 @@ def test_empty_against(runtmp, capfd):
against_list = runtmp.output('against.txt')
make_file_list(against_list, [])

runtmp.sourmash('scripts', 'fastmultigather', query_list, against_list,
with pytest.raises(utils.SourmashCommandFailed):
runtmp.sourmash('scripts', 'fastmultigather', query_list, against_list,
'-s', '100000')

captured = capfd.readouterr()
Expand Down
5 changes: 3 additions & 2 deletions src/python/tests/test_multisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def test_bad_against(runtmp, capfd):


def test_empty_query(runtmp, capfd):
# test with an empty query list - fail gracefully
# test with an empty query list - fail with error
query_list = runtmp.output('query.txt')
against_list = runtmp.output('against.txt')

Expand All @@ -434,7 +434,8 @@ def test_empty_query(runtmp, capfd):

output = runtmp.output('out.csv')

runtmp.sourmash('scripts', 'multisearch', query_list, against_list,
with pytest.raises(utils.SourmashCommandFailed):
runtmp.sourmash('scripts', 'multisearch', query_list, against_list,
'-o', output)

print(runtmp.last_result.err)
Expand Down
6 changes: 4 additions & 2 deletions src/python/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ def test_nomatch_against(runtmp, capfd):

output = runtmp.output('out.csv')

runtmp.sourmash('scripts', 'manysearch', query_list, against_list,
with pytest.raises(utils.SourmashCommandFailed):
runtmp.sourmash('scripts', 'manysearch', query_list, against_list,
'-o', output)

captured = capfd.readouterr()
Expand Down Expand Up @@ -470,7 +471,8 @@ def test_empty_query(runtmp, indexed, capfd):

output = runtmp.output('out.csv')

runtmp.sourmash('scripts', 'manysearch', query_list, against_list,
with pytest.raises(utils.SourmashCommandFailed):
runtmp.sourmash('scripts', 'manysearch', query_list, against_list,
'-o', output)

print(runtmp.last_result.err)
Expand Down
3 changes: 1 addition & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,7 @@ pub fn report_on_collection_loading(

// Validate sketches
if collection.is_empty() {
eprintln!("No {} signatures loaded, exiting.", report_type);
return Ok(());
bail!("No {} signatures loaded, exiting.", report_type);
}
eprintln!("Loaded {} {} signature(s)", collection.len(), report_type);
Ok(())
Expand Down

0 comments on commit 4004e85

Please sign in to comment.