Skip to content

Commit

Permalink
prepare_operations: avoid crash when no rasters provided
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Aug 29, 2024
1 parent 8bec482 commit 399d0cb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ prepare_operations(
const RasterSourceVect& rasters,
const RasterSourceVect& weights)
{
if (!descriptors.empty() && rasters.empty()) {
throw std::runtime_error("no rasters provided to prepare_operations");
}

std::vector<std::unique_ptr<Operation>> ops;

std::vector<StatDescriptor> parsed_descriptors;
Expand Down
10 changes: 10 additions & 0 deletions test/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@ TEST_CASE("prepare_operations")
CHECK(ops[0]->name == "mean");
CHECK(ops[1]->name == "adj_mean");
}

SECTION("error when no rasters are provided")
{
auto values = make_rasters("v", 0);
std::vector<std::unique_ptr<RasterSource>> weights;
std::vector<std::string> stats{ "sum" };

CHECK_THROWS_WITH(prepare_operations(stats, values, weights),
Catch::Contains("no rasters provided"));
}
}

TEST_CASE("parsing arguments")
Expand Down

0 comments on commit 399d0cb

Please sign in to comment.