diff --git a/rcl_logging_interface/include/rcl_logging_interface/rcl_logging_interface.h b/rcl_logging_interface/include/rcl_logging_interface/rcl_logging_interface.h index 11c1782..3498dc2 100644 --- a/rcl_logging_interface/include/rcl_logging_interface/rcl_logging_interface.h +++ b/rcl_logging_interface/include/rcl_logging_interface/rcl_logging_interface.h @@ -45,7 +45,8 @@ typedef enum * an rcutils_allocator_t rather than an rcl_allocator_t to ensure that the * rcl_logging_* packages don't have a circular dependency back to rcl. * \return RCL_LOGGING_RET_OK if initialized successfully. - * \return RCL_LOGGING_RET_ERROR if an unspecified error occurs. + * \return RCL_LOGGING_RET_ERROR if an unspecified error occurs. An rcutils error message will be + * set. * \return RCL_LOGGING_RET_CONFIG_FILE_DOESNT_EXIST if a config_file is provided * but the file doesn't exist. * \return RCL_LOGGING_RET_CONFIG_FILE_INVALID if a config_file is provided but diff --git a/rcl_logging_spdlog/src/rcl_logging_spdlog.cpp b/rcl_logging_spdlog/src/rcl_logging_spdlog.cpp index af94684..8f7b4b8 100644 --- a/rcl_logging_spdlog/src/rcl_logging_spdlog.cpp +++ b/rcl_logging_spdlog/src/rcl_logging_spdlog.cpp @@ -133,7 +133,7 @@ rcl_logging_ret_t rcl_logging_external_initialize( if (RCL_LOGGING_RET_OK != dir_ret) { // We couldn't get the log directory, so get out of here without setting up // logging. - RCUTILS_SET_ERROR_MSG("Failed to get logging directory"); + RCUTILS_SET_ERROR_MSG_AND_APPEND_PREV_ERROR("Failed to get logging directory"); return dir_ret; } RCPPUTILS_SCOPE_EXIT( diff --git a/rcl_logging_spdlog/test/test_logging_interface.cpp b/rcl_logging_spdlog/test/test_logging_interface.cpp index 71bd01f..fb02634 100644 --- a/rcl_logging_spdlog/test/test_logging_interface.cpp +++ b/rcl_logging_spdlog/test/test_logging_interface.cpp @@ -68,14 +68,17 @@ TEST_F(LoggingTest, init_invalid) EXPECT_EQ( RCL_LOGGING_RET_ERROR, rcl_logging_external_initialize(nullptr, "anything", allocator)); + EXPECT_TRUE(rcutils_error_is_set()); rcutils_reset_error(); EXPECT_EQ( RCL_LOGGING_RET_ERROR, rcl_logging_external_initialize("anything", nullptr, bad_allocator)); + EXPECT_TRUE(rcutils_error_is_set()); rcutils_reset_error(); EXPECT_EQ( RCL_LOGGING_RET_ERROR, rcl_logging_external_initialize(nullptr, nullptr, invalid_allocator)); + EXPECT_TRUE(rcutils_error_is_set()); rcutils_reset_error(); } @@ -88,6 +91,7 @@ TEST_F(LoggingTest, init_failure) ASSERT_EQ(true, rcutils_set_env("HOME", nullptr)); ASSERT_EQ(true, rcutils_set_env("USERPROFILE", nullptr)); EXPECT_EQ(RCL_LOGGING_RET_ERROR, rcl_logging_external_initialize(nullptr, nullptr, allocator)); + EXPECT_TRUE(rcutils_error_is_set()); rcutils_reset_error(); // Force failure to create directories @@ -99,6 +103,8 @@ TEST_F(LoggingTest, init_failure) std::filesystem::path ros_dir = fake_home / ".ros"; std::fstream(ros_dir.string(), std::ios_base::out).close(); EXPECT_EQ(RCL_LOGGING_RET_ERROR, rcl_logging_external_initialize(nullptr, nullptr, allocator)); + EXPECT_TRUE(rcutils_error_is_set()); + rcutils_reset_error(); ASSERT_TRUE(std::filesystem::remove(ros_dir)); // ...fail to create .ros/log dir @@ -106,6 +112,8 @@ TEST_F(LoggingTest, init_failure) std::filesystem::path ros_log_dir = ros_dir / "log"; std::fstream(ros_log_dir.string(), std::ios_base::out).close(); EXPECT_EQ(RCL_LOGGING_RET_ERROR, rcl_logging_external_initialize(nullptr, nullptr, allocator)); + EXPECT_TRUE(rcutils_error_is_set()); + rcutils_reset_error(); ASSERT_TRUE(std::filesystem::remove(ros_log_dir)); ASSERT_TRUE(std::filesystem::remove(ros_dir));