Skip to content

Commit

Permalink
fix: error handling when using compression with metadata requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Jan 4, 2024
1 parent 2a9f301 commit 4868612
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/mkdwarfs_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,18 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) {
categorizer_list.add_implicit_defaults(cop);
LOG_VERBOSE << cop.as_string();

fsw->add_default_compressor(compression_opt.get());
{
auto bc = compression_opt.get();

if (!bc.metadata_requirements().empty()) {
throw std::runtime_error(
fmt::format("compression '{}' cannot be used without a category: "
"metadata requirements not met",
bc.describe()));
}

fsw->add_default_compressor(std::move(bc));
}

if (recompress) {
compression_opt.visit_contextual(
Expand Down
7 changes: 7 additions & 0 deletions test/tool_main_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,3 +1071,10 @@ TEST(mkdwarfs_test, output_file_fail_close) {
EXPECT_NE(0, t.run({"-i", "/", "-o", "test.dwarfs"})) << t.err();
EXPECT_THAT(t.err(), ::testing::HasSubstr("failed to close output file"));
}

TEST(mkdwarfs_test, compression_cannot_be_used) {
mkdwarfs_tester t;
EXPECT_NE(0, t.run({"-i", "/", "-o", "-", "-C", "flac"}));
EXPECT_THAT(t.err(),
::testing::HasSubstr("cannot be used without a category"));
}

0 comments on commit 4868612

Please sign in to comment.