Skip to content

Commit 9fff868

Browse files
committed
libutil: Add missing format arguments to UsageError ctor
Once again found by an automated migration to `std::format`. I've tested that boost::format works fine with `std::string_view` arguments.
1 parent 2704757 commit 9fff868

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/libutil-tests/file-content-address.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <gmock/gmock.h>
12
#include <gtest/gtest.h>
23

34
#include "nix/util/file-content-address.hh"
@@ -26,8 +27,11 @@ TEST(FileSerialisationMethod, testRoundTripPrintParse_2) {
2627
}
2728
}
2829

29-
TEST(FileSerialisationMethod, testParseFileSerialisationMethodOptException) {
30-
EXPECT_THROW(parseFileSerialisationMethod("narwhal"), UsageError);
30+
TEST(FileSerialisationMethod, testParseFileSerialisationMethodOptException)
31+
{
32+
EXPECT_THAT(
33+
[]() { parseFileSerialisationMethod("narwhal"); },
34+
testing::ThrowsMessage<UsageError>(testing::HasSubstr("narwhal")));
3135
}
3236

3337
/* ----------------------------------------------------------------------------
@@ -54,8 +58,11 @@ TEST(FileIngestionMethod, testRoundTripPrintParse_2) {
5458
}
5559
}
5660

57-
TEST(FileIngestionMethod, testParseFileIngestionMethodOptException) {
58-
EXPECT_THROW(parseFileIngestionMethod("narwhal"), UsageError);
61+
TEST(FileIngestionMethod, testParseFileIngestionMethodOptException)
62+
{
63+
EXPECT_THAT(
64+
[]() { parseFileIngestionMethod("narwhal"); },
65+
testing::ThrowsMessage<UsageError>(testing::HasSubstr("narwhal")));
5966
}
6067

6168
}

src/libutil/file-content-address.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ FileSerialisationMethod parseFileSerialisationMethod(std::string_view input)
2222
if (ret)
2323
return *ret;
2424
else
25-
throw UsageError("Unknown file serialiation method '%s', expect `flat` or `nar`");
25+
throw UsageError("Unknown file serialiation method '%s', expect `flat` or `nar`", input);
2626
}
2727

2828

@@ -35,7 +35,7 @@ FileIngestionMethod parseFileIngestionMethod(std::string_view input)
3535
if (ret)
3636
return static_cast<FileIngestionMethod>(*ret);
3737
else
38-
throw UsageError("Unknown file ingestion method '%s', expect `flat`, `nar`, or `git`");
38+
throw UsageError("Unknown file ingestion method '%s', expect `flat`, `nar`, or `git`", input);
3939
}
4040
}
4141

0 commit comments

Comments
 (0)