From 4004e85d32366a01d42d601ea9b133014e31ce47 Mon Sep 17 00:00:00 2001 From: Tessa Pierce Ward Date: Wed, 20 Mar 2024 14:30:17 -0700 Subject: [PATCH] MRG: fail-exit when 0 signatures are loaded from a collection (#282) 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 --- src/index.rs | 7 ------- src/python/tests/test_multigather.py | 3 ++- src/python/tests/test_multisearch.py | 5 +++-- src/python/tests/test_search.py | 6 ++++-- src/utils.rs | 3 +-- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/index.rs b/src/index.rs index 3b2aa4a5..3747e6f5 100644 --- a/src/index.rs +++ b/src/index.rs @@ -20,13 +20,6 @@ pub fn index>( 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()?, diff --git a/src/python/tests/test_multigather.py b/src/python/tests/test_multigather.py index 486d023c..d50ce5c0 100644 --- a/src/python/tests/test_multigather.py +++ b/src/python/tests/test_multigather.py @@ -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() diff --git a/src/python/tests/test_multisearch.py b/src/python/tests/test_multisearch.py index 932692c0..611b0f81 100644 --- a/src/python/tests/test_multisearch.py +++ b/src/python/tests/test_multisearch.py @@ -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') @@ -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) diff --git a/src/python/tests/test_search.py b/src/python/tests/test_search.py index c3cd79f4..8e08e714 100644 --- a/src/python/tests/test_search.py +++ b/src/python/tests/test_search.py @@ -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() @@ -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) diff --git a/src/utils.rs b/src/utils.rs index 4c1bb912..c05b5fc3 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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(())