diff --git a/mindspore/ccsrc/debug/env_config_parser.cc b/mindspore/ccsrc/debug/env_config_parser.cc index 4e13787ba7..4abb585874 100644 --- a/mindspore/ccsrc/debug/env_config_parser.cc +++ b/mindspore/ccsrc/debug/env_config_parser.cc @@ -38,12 +38,13 @@ bool EnvConfigParser::CheckJsonStringType(const nlohmann::json &content, const s return true; } -auto EnvConfigParser::CheckJsonKeyExist(const nlohmann::json &content, const std::string &setting_key, - const std::string &key) { +std::optional> EnvConfigParser::CheckJsonKeyExist( + const nlohmann::json &content, const std::string &setting_key, const std::string &key) { auto iter = content.find(key); if (iter == content.end()) { MS_LOG(WARNING) << "Check json failed, '" << key << "' not found in '" << setting_key << "'." << " Please check the config file '" << config_file_ << "' set by 'env_config_path' in context."; + return std::nullopt; } return iter; } @@ -104,10 +105,14 @@ void EnvConfigParser::ParseRdrSetting(const nlohmann::json &content) { } auto rdr_enable = CheckJsonKeyExist(*rdr_setting, kRdrSettings, kEnable); - auto rdr_path = CheckJsonKeyExist(*rdr_setting, kRdrSettings, kPath); + if (rdr_enable.has_value()) { + ParseRdrEnable(**rdr_enable); + } - ParseRdrEnable(*rdr_enable); - ParseRdrPath(*rdr_path); + auto rdr_path = CheckJsonKeyExist(*rdr_setting, kRdrSettings, kPath); + if (rdr_path.has_value()) { + ParseRdrPath(**rdr_path); + } } void EnvConfigParser::ParseRdrPath(const nlohmann::json &content) { diff --git a/mindspore/ccsrc/debug/env_config_parser.h b/mindspore/ccsrc/debug/env_config_parser.h index 83f2406060..a3744a091e 100644 --- a/mindspore/ccsrc/debug/env_config_parser.h +++ b/mindspore/ccsrc/debug/env_config_parser.h @@ -49,7 +49,9 @@ class EnvConfigParser { void ParseRdrSetting(const nlohmann::json &content); bool CheckJsonStringType(const nlohmann::json &content, const std::string &setting_key, const std::string &key); - auto CheckJsonKeyExist(const nlohmann::json &content, const std::string &setting_key, const std::string &key); + std::optional> CheckJsonKeyExist(const nlohmann::json &content, + const std::string &setting_key, + const std::string &key); void ParseRdrPath(const nlohmann::json &content); void ParseRdrEnable(const nlohmann::json &content);