fix: Skip misformatted configuration files (#3580)

Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
Co-authored-by: Chaoneng Quan <chaonengquan@Chaonengs-MacBook-Pro.local>
This commit is contained in:
ChaonengQuan 2024-11-12 01:16:22 -08:00 committed by GitHub
parent a638f702e2
commit 554d9264da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -2338,6 +2338,14 @@ namespace mamba
strStream << inFile.rdbuf();
std::string s = strStream.str();
config = YAML::Load(expandvars(s));
if (config.IsScalar())
{
LOG_WARNING << fmt::format(
"The configuration file at {} is misformatted or corrupted. Skipping file.",
file.string()
);
return YAML::Node();
}
}
catch (const std::exception& ex)
{

View File

@ -918,6 +918,15 @@ namespace mamba
util::unset_env("MAMBA_CHANNEL_PRIORITY");
}
TEST_CASE_FIXTURE(Configuration, "skip_misformatted_config_file")
{
std::string rc = "invalid_scalar_value";
load_test_config(rc);
CHECK_EQ(config.sources().size(), 1);
CHECK_EQ(config.valid_sources().size(), 0);
CHECK_EQ(config.dump(), "");
}
TEST_CASE_FIXTURE(Configuration, "pinned_packages")
{
std::string rc1 = unindent(R"(