Skip to content

fix(agnocastlib): error handling agnocastlib#1138

Open
Koichi98 wants to merge 13 commits intomainfrom
fix/error_handling_agnocastlib
Open

fix(agnocastlib): error handling agnocastlib#1138
Koichi98 wants to merge 13 commits intomainfrom
fix/error_handling_agnocastlib

Conversation

@Koichi98
Copy link
Copy Markdown
Collaborator

@Koichi98 Koichi98 commented Feb 28, 2026

Description

Replace exit(EXIT_FAILURE) with exception throwing in agnocastlib for better error handling.

Changes

  • Error handling: Changed from RCLCPP_ERROR + exit() to throwing exceptions
  • Exception types:
    • std::runtime_error: Runtime errors (ioctl/mq_open/shm failures)
    • std::invalid_argument: Invalid arguments from caller (invalid message, unsupported QoS, callback group not in node)
    • std::logic_error: Programming errors (publish without borrow_loaned_message)
  • Exception catching: Widened catch (ComponentManagerException) to catch (std::exception) in component containers
  • Worker thread safety: Added try/catch in worker threads of multi-threaded and callback-isolated executors to prevent std::terminate() from uncaught exceptions. Uses std::atomic<bool> flag to propagate failure to the main thread, which rethrows after joining so that main() can perform cleanup (close(agnocast_fd)) and exit with EXIT_FAILURE
  • Test updates: Changed EXPECT_EXIT(..., ExitedWithCode(EXIT_FAILURE), ...) to EXPECT_THROW(..., <exception_type>) for tests that verify error handling behavior

Related links

How was this PR tested?

  • Autoware (required)
  • bash scripts/test/e2e_test_1to1 (required)
  • bash scripts/test/e2e_test_2to2 (required)
  • kunit tests (required when modifying the kernel module)
  • sample application

Notes for reviewers

Version Update Label (Required)

Please add exactly one of the following labels to this PR:

  • need-major-update: User API breaking changes
  • need-minor-update: Internal API breaking changes (heaphook/kmod/agnocastlib compatibility)
  • need-patch-update: Bug fixes and other changes

Important notes:

  • If you need need-major-update or need-minor-update, please include this in the PR title as well.
    • Example: fix(foo)[needs major version update]: bar or feat(baz)[needs minor version update]: qux
  • After receiving approval from reviewers, add the run-build-test label. The PR can only be merged after the build tests pass.

See CONTRIBUTING.md for detailed versioning rules.

Signed-off-by: Koichi <koichi.imai.2@tier4.jp>
Signed-off-by: Koichi <koichi.imai.2@tier4.jp>
Signed-off-by: Koichi <koichi.imai.2@tier4.jp>
Koichi98 and others added 3 commits March 1, 2026 01:35
Signed-off-by: Koichi <koichi.imai.2@tier4.jp>
Signed-off-by: Koichi <koichi.imai.2@tier4.jp>
@Koichi98 Koichi98 changed the title Fix/error handling agnocastlib fix(agnocastlib): error handling agnocastlib Mar 1, 2026
@Koichi98 Koichi98 added the need-patch-update Bug fixes and other changes - requires PATCH version update label Mar 1, 2026
Signed-off-by: Koichi Imai <koichi.imai.2@tier4.jp>
@Koichi98 Koichi98 marked this pull request as ready for review March 1, 2026 06:02
Copilot AI review requested due to automatic review settings March 1, 2026 06:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces exit(EXIT_FAILURE) calls in agnocastlib with thrown C++ exceptions to enable proper error propagation. Previously, any failure in agnocastlib would immediately kill the process; now errors can be caught and handled upstream.

Changes:

  • Exception replacement: All RCLCPP_ERROR + close(agnocast_fd) + exit(EXIT_FAILURE) patterns replaced with throw std::runtime_error (for ioctl/mq/shm failures) or throw std::invalid_argument (for invalid caller arguments).
  • Widened catch blocks: Four component containers (both in agnocastlib and agnocast_components) changed from catch (rclcpp_components::ComponentManagerException&) to catch (const std::exception&) to intercept the newly thrown exceptions.
  • New <stdexcept> include: Added to agnocast_utils.hpp to make exception types available throughout the header chain.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/agnocastlib/src/agnocast_utils.cpp Replaces exit() with throw std::runtime_error in validate_ld_preload and create_mq_name
src/agnocastlib/src/agnocast_subscription.cpp Replaces exit() with throw std::runtime_error in initialize, get_publisher_count_core, open_mq_for_subscription
src/agnocastlib/src/agnocast_publisher.cpp Replaces exit() with throw std::runtime_error in initialize_publisher, publish_core, get_subscription_count_core, get_intra_subscription_count_core
src/agnocastlib/src/agnocast_client.cpp Replaces exit() with throw std::runtime_error in get_agnocast_sub_count
src/agnocastlib/src/agnocast_callback_info.cpp Replaces exit() with throw std::runtime_error in receive_and_execute_message
src/agnocastlib/include/agnocast/agnocast_utils.hpp Adds <stdexcept> include; replaces exit() with throw std::invalid_argument in validate_qos
src/agnocastlib/include/agnocast/agnocast_subscription.hpp Replaces exit() with throw std::invalid_argument in get_valid_callback_group; replaces exit() with throw std::runtime_error in BasicTakeSubscription::take
src/agnocastlib/include/agnocast/agnocast_publisher.hpp Replaces exit() with throw std::invalid_argument in BasicPublisher::publish
src/agnocastlib/include/agnocast/agnocast_callback_info.hpp Replaces exit() with throw std::runtime_error in get_erased_callback
src/agnocastlib/src/agnocast_component_container.cpp Widens catch from ComponentManagerException to std::exception
src/agnocastlib/src/agnocast_component_container_mt.cpp Widens catch from ComponentManagerException to std::exception
src/agnocast_components/src/agnocast_component_container.cpp Widens catch from ComponentManagerException to std::exception
src/agnocast_components/src/agnocast_component_container_mt.cpp Widens catch from ComponentManagerException to std::exception

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/agnocastlib/src/agnocast_utils.cpp Outdated
Comment thread src/agnocastlib/src/agnocast_utils.cpp
Comment thread src/agnocastlib/src/agnocast_utils.cpp Outdated
Comment thread src/agnocastlib/include/agnocast/agnocast_publisher.hpp
Comment thread src/agnocastlib/include/agnocast/agnocast_subscription.hpp
Comment thread src/agnocastlib/include/agnocast/agnocast_callback_info.hpp
Comment thread src/agnocastlib/src/agnocast_callback_info.cpp
Signed-off-by: Koichi Imai <koichi.imai.2@tier4.jp>
@Koichi98 Koichi98 removed their assignment Mar 1, 2026
Koichi98 and others added 5 commits March 1, 2026 15:12
Signed-off-by: Koichi Imai <koichi.imai.2@tier4.jp>
Signed-off-by: Koichi Imai <koichi.imai.2@tier4.jp>
Signed-off-by: Koichi Imai <koichi.imai.2@tier4.jp>
Signed-off-by: Koichi Imai <koichi.imai.2@tier4.jp>
@Koichi98 Koichi98 self-assigned this Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need-patch-update Bug fixes and other changes - requires PATCH version update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants