diff --git a/error_manager/error_manager.cc b/error_manager/error_manager.cc index 2c7a2e1228302ffaa03d4c215c4a5d04e7fed2c9..f786a6ca414eedfbecfe3b51804a246c627d2e08 100644 --- a/error_manager/error_manager.cc +++ b/error_manager/error_manager.cc @@ -204,6 +204,10 @@ ErrorManager &ErrorManager::GetInstance() { /// @return int 0(success) -1(fail) /// int32_t ErrorManager::Init(const std::string path) { + if (is_init_) { + return 0; + } + const std::string file_path = path + kErrorCodePath; const int32_t ret = ParseJsonFile(file_path); if (ret != 0) { diff --git a/tests/ut/error_manager/testcase/error_manager_unittest.cc b/tests/ut/error_manager/testcase/error_manager_unittest.cc index 20d1d816698784d2effc7344bbfecbc53dd05843..3b40855dcbd4506fed5d4c80f67c07b0b10401da 100644 --- a/tests/ut/error_manager/testcase/error_manager_unittest.cc +++ b/tests/ut/error_manager/testcase/error_manager_unittest.cc @@ -40,8 +40,8 @@ TEST_F(UtestErrorManager, Init_faild) { auto &instance = ErrorManager::GetInstance(); EXPECT_EQ(instance.Init(""), -1); instance.is_init_ = true; - EXPECT_EQ(instance.Init(""), -1); - EXPECT_EQ(instance.Init(), -1); + EXPECT_EQ(instance.Init(""), 0); + EXPECT_EQ(instance.Init(), 0); } TEST_F(UtestErrorManager, FormatErrorMessage) {