[expected] Now uses exit variants instead of throw variants

This commit is contained in:
Alexander Karatarakis 2017-03-28 12:57:00 -07:00
parent db4d1df5f0
commit 67ce764c2e
9 changed files with 30 additions and 30 deletions

View File

@ -40,15 +40,15 @@ namespace vcpkg
return this->m_error_code;
}
T&& get_or_throw(const LineInfo& line_info) &&
T&& get_or_exit(const LineInfo& line_info) &&
{
throw_if_error(line_info);
exit_if_error(line_info);
return std::move(this->m_t);
}
const T& get_or_throw(const LineInfo& line_info) const &
const T& get_or_exit(const LineInfo& line_info) const &
{
throw_if_error(line_info);
exit_if_error(line_info);
return this->m_t;
}
@ -71,9 +71,9 @@ namespace vcpkg
}
private:
void throw_if_error(const LineInfo& line_info) const
void exit_if_error(const LineInfo& line_info) const
{
Checks::check_throw(line_info, !this->m_error_code, this->m_error_code.message().c_str());
Checks::check_exit(line_info, !this->m_error_code, this->m_error_code.message());
}
std::error_code m_error_code;

View File

@ -31,7 +31,7 @@ namespace vcpkg
const std::string architecture = details::remove_required_field(&fields, BinaryParagraphRequiredField::ARCHITECTURE);
const triplet target_triplet = triplet::from_canonical_name(architecture);
this->spec = package_spec::from_name_and_triplet(name, target_triplet).get_or_throw(VCPKG_LINE_INFO);
this->spec = package_spec::from_name_and_triplet(name, target_triplet).get_or_exit(VCPKG_LINE_INFO);
this->version = details::remove_required_field(&fields, BinaryParagraphRequiredField::VERSION);
this->description = details::remove_optional_field(&fields, BinaryParagraphOptionalField::DESCRIPTION);
@ -46,7 +46,7 @@ namespace vcpkg
BinaryParagraph::BinaryParagraph(const SourceParagraph& spgh, const triplet& target_triplet)
{
this->spec = package_spec::from_name_and_triplet(spgh.name, target_triplet).get_or_throw(VCPKG_LINE_INFO);
this->spec = package_spec::from_name_and_triplet(spgh.name, target_triplet).get_or_exit(VCPKG_LINE_INFO);
this->version = spgh.version;
this->description = spgh.description;
this->maintainer = spgh.maintainer;

View File

@ -20,7 +20,7 @@ namespace vcpkg::Commands::CI
std::vector<package_spec> specs;
for (const SourceParagraph& p : ports)
{
specs.push_back(package_spec::from_name_and_triplet(p.name, target_triplet).get_or_throw(VCPKG_LINE_INFO));
specs.push_back(package_spec::from_name_and_triplet(p.name, target_triplet).get_or_exit(VCPKG_LINE_INFO));
}
return specs;
@ -70,7 +70,7 @@ namespace vcpkg::Commands::CI
System::println(System::color::error, Build::create_error_message(result, action.spec));
continue;
}
const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).get_or_throw(VCPKG_LINE_INFO);
const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).get_or_exit(VCPKG_LINE_INFO);
Install::install_package(paths, bpgh, &status_db);
System::println(System::color::success, "Package %s is installed", action.spec);
}

View File

@ -223,7 +223,7 @@ namespace vcpkg::Commands::Install
System::println(Build::create_user_troubleshooting_message(action.spec));
Checks::exit_fail(VCPKG_LINE_INFO);
}
const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).get_or_throw(VCPKG_LINE_INFO);
const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).get_or_exit(VCPKG_LINE_INFO);
install_package(paths, bpgh, &status_db);
System::println(System::color::success, "Package %s is installed", action.spec);
}

View File

@ -153,14 +153,14 @@ namespace UnitTest1
TEST_METHOD(parse_paragraphs_empty)
{
const char* str = "";
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_throw(VCPKG_LINE_INFO);
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_exit(VCPKG_LINE_INFO);
Assert::IsTrue(pghs.empty());
}
TEST_METHOD(parse_paragraphs_one_field)
{
const char* str = "f1: v1";
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_throw(VCPKG_LINE_INFO);
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_exit(VCPKG_LINE_INFO);
Assert::AreEqual(size_t(1), pghs.size());
Assert::AreEqual(size_t(1), pghs[0].size());
Assert::AreEqual("v1", pghs[0]["f1"].c_str());
@ -171,7 +171,7 @@ namespace UnitTest1
const char* str =
"f1: v1\n"
"f2: v2";
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_throw(VCPKG_LINE_INFO);
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_exit(VCPKG_LINE_INFO);
Assert::AreEqual(size_t(1), pghs.size());
Assert::AreEqual(size_t(2), pghs[0].size());
Assert::AreEqual("v1", pghs[0]["f1"].c_str());
@ -186,7 +186,7 @@ namespace UnitTest1
"\n"
"f3: v3\n"
"f4: v4";
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_throw(VCPKG_LINE_INFO);
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_exit(VCPKG_LINE_INFO);
Assert::AreEqual(size_t(2), pghs.size());
Assert::AreEqual(size_t(2), pghs[0].size());
Assert::AreEqual("v1", pghs[0]["f1"].c_str());
@ -204,7 +204,7 @@ namespace UnitTest1
"F:\n"
"0:\n"
"F-2:\n";
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_throw(VCPKG_LINE_INFO);
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_exit(VCPKG_LINE_INFO);
Assert::AreEqual(size_t(1), pghs.size());
Assert::AreEqual(size_t(5), pghs[0].size());
}
@ -218,7 +218,7 @@ namespace UnitTest1
"\n"
"f3: v3\n"
"f4: v4";
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_throw(VCPKG_LINE_INFO);
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_exit(VCPKG_LINE_INFO);
Assert::AreEqual(size_t(2), pghs.size());
}
@ -227,7 +227,7 @@ namespace UnitTest1
const char* str =
"f1:\n"
"f2: ";
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_throw(VCPKG_LINE_INFO);
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_exit(VCPKG_LINE_INFO);
Assert::AreEqual(size_t(1), pghs.size());
Assert::AreEqual(size_t(2), pghs[0].size());
Assert::AreEqual("", pghs[0]["f1"].c_str());
@ -243,7 +243,7 @@ namespace UnitTest1
"f2:\r\n"
" f2\r\n"
" continue\r\n";
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_throw(VCPKG_LINE_INFO);
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_exit(VCPKG_LINE_INFO);
Assert::AreEqual(size_t(1), pghs.size());
Assert::AreEqual("simple\n f1", pghs[0]["f1"].c_str());
Assert::AreEqual("\n f2\n continue", pghs[0]["f2"].c_str());
@ -257,7 +257,7 @@ namespace UnitTest1
"\r\n"
"f3: v3\r\n"
"f4: v4";
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_throw(VCPKG_LINE_INFO);
auto pghs = vcpkg::Paragraphs::parse_paragraphs(str).get_or_exit(VCPKG_LINE_INFO);
Assert::AreEqual(size_t(2), pghs.size());
Assert::AreEqual(size_t(2), pghs[0].size());
Assert::AreEqual("v1", pghs[0]["f1"].c_str());
@ -277,7 +277,7 @@ namespace UnitTest1
{"Multi-Arch", "same"},
});
ss << pgh;
auto pghs = vcpkg::Paragraphs::parse_paragraphs(ss.str()).get_or_throw(VCPKG_LINE_INFO);
auto pghs = vcpkg::Paragraphs::parse_paragraphs(ss.str()).get_or_exit(VCPKG_LINE_INFO);
Assert::AreEqual(size_t(1), pghs.size());
Assert::AreEqual(size_t(4), pghs[0].size());
Assert::AreEqual("zlib", pghs[0]["Package"].c_str());
@ -299,7 +299,7 @@ namespace UnitTest1
{"Multi-Arch", "same"},
});
ss << pgh;
auto pghs = vcpkg::Paragraphs::parse_paragraphs(ss.str()).get_or_throw(VCPKG_LINE_INFO);
auto pghs = vcpkg::Paragraphs::parse_paragraphs(ss.str()).get_or_exit(VCPKG_LINE_INFO);
Assert::AreEqual(size_t(1), pghs.size());
Assert::AreEqual(size_t(7), pghs[0].size());
Assert::AreEqual("zlib", pghs[0]["Package"].c_str());
@ -321,7 +321,7 @@ namespace UnitTest1
{"Depends", "a, b, c"},
});
ss << pgh;
auto pghs = vcpkg::Paragraphs::parse_paragraphs(ss.str()).get_or_throw(VCPKG_LINE_INFO);
auto pghs = vcpkg::Paragraphs::parse_paragraphs(ss.str()).get_or_exit(VCPKG_LINE_INFO);
Assert::AreEqual(size_t(1), pghs.size());
Assert::AreEqual("a, b, c", pghs[0]["Depends"].c_str());
}

View File

@ -60,7 +60,7 @@ static void inner(const vcpkg_cmd_arguments& args)
const expected<vcpkg_paths> expected_paths = vcpkg_paths::create(vcpkg_root_dir);
Checks::check_exit(VCPKG_LINE_INFO, !expected_paths.error_code(), "Error: Invalid vcpkg root directory %s: %s", vcpkg_root_dir.string(), expected_paths.error_code().message());
const vcpkg_paths paths = expected_paths.get_or_throw(VCPKG_LINE_INFO);
const vcpkg_paths paths = expected_paths.get_or_exit(VCPKG_LINE_INFO);
int exit_code = _wchdir(paths.root.c_str());
Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Changing the working dir failed");
@ -111,7 +111,7 @@ static void loadConfig()
try
{
auto pghs = Paragraphs::get_paragraphs(localappdata / "vcpkg" / "config").get_or_throw(VCPKG_LINE_INFO);
auto pghs = Paragraphs::get_paragraphs(localappdata / "vcpkg" / "config").get_or_exit(VCPKG_LINE_INFO);
std::unordered_map<std::string, std::string> keys;
if (pghs.size() > 0)
keys = pghs[0];

View File

@ -56,7 +56,7 @@ namespace vcpkg::Dependencies
{
for (const std::string& dep_as_string : dependencies_as_string)
{
const package_spec current_dep = package_spec::from_name_and_triplet(dep_as_string, spec.target_triplet()).get_or_throw(VCPKG_LINE_INFO);
const package_spec current_dep = package_spec::from_name_and_triplet(dep_as_string, spec.target_triplet()).get_or_exit(VCPKG_LINE_INFO);
graph.add_edge(spec, current_dep);
if (was_examined.find(current_dep) == was_examined.end())
{

View File

@ -13,5 +13,5 @@ int WINAPI WinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPSTR, _In_ int)
szArgList = CommandLineToArgvW(GetCommandLineW(), &argCount);
Checks::check_exit(VCPKG_LINE_INFO, argCount == 2, "Requires exactly one argument, the path to the payload file");
Upload(Files::read_contents(szArgList[1]).get_or_throw(VCPKG_LINE_INFO));
Upload(Files::read_contents(szArgList[1]).get_or_exit(VCPKG_LINE_INFO));
}

View File

@ -22,7 +22,7 @@ namespace vcpkg
fs::rename(vcpkg_dir_status_file_old, vcpkg_dir_status_file);
}
auto pghs = Paragraphs::get_paragraphs(vcpkg_dir_status_file).get_or_throw(VCPKG_LINE_INFO);
auto pghs = Paragraphs::get_paragraphs(vcpkg_dir_status_file).get_or_exit(VCPKG_LINE_INFO);
std::vector<std::unique_ptr<StatusParagraph>> status_pghs;
for (auto&& p : pghs)
@ -64,7 +64,7 @@ namespace vcpkg
if (b->path().filename() == "incomplete")
continue;
auto pghs = Paragraphs::get_paragraphs(b->path()).get_or_throw(VCPKG_LINE_INFO);
auto pghs = Paragraphs::get_paragraphs(b->path()).get_or_exit(VCPKG_LINE_INFO);
for (auto&& p : pghs)
{
current_status_db.insert(std::make_unique<StatusParagraph>(p));
@ -183,7 +183,7 @@ namespace vcpkg
}
const fs::path listfile_path = paths.listfile_path(pgh->package);
std::vector<std::string> installed_files_of_current_pgh = Files::read_all_lines(listfile_path).get_or_throw(VCPKG_LINE_INFO);
std::vector<std::string> installed_files_of_current_pgh = Files::read_all_lines(listfile_path).get_or_exit(VCPKG_LINE_INFO);
Strings::trim_all_and_remove_whitespace_strings(&installed_files_of_current_pgh);
upgrade_to_slash_terminated_sorted_format(&installed_files_of_current_pgh, listfile_path);