Skip to content

Conversation

@maxkozlovsky
Copy link
Contributor

Mark Rust ffi function as noexcept to prevent exception propagation to Rust code. Any unhandled exceptions will result in direct call to terminate().

This commit adds a custom terminate handler that provides detailed diagnostics when std::terminate() is called. This helps debug issues where exceptions escape noexcept functions or cross FFI boundaries.

The handler is installed via monad_set_terminate_handler() which should be called early in main() before any exception-throwing code.

This code was generated using Claude Sonnet 4.5

Copilot AI review requested due to automatic review settings November 3, 2025 21:30
Copy link

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 refactors terminate handler functionality and adds noexcept specifications to C API functions. The terminate handler implementation is extracted from main.cpp into a reusable module, and noexcept is added to functions crossing the C/C++ FFI boundary to ensure exceptions don't escape.

  • Extracted terminate handler logic into a new category/core/terminate_handler module
  • Added noexcept specifications to all C API functions in statesync and RPC modules
  • Created a manual test to demonstrate the terminate handler functionality

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cmd/monad/main.cpp Replaced inline terminate handler with call to new monad_set_terminate_handler() function
category/core/terminate_handler.h New header defining the terminate handler setup function
category/core/terminate_handler.cpp New implementation with enhanced exception reporting and backtrace printing
category/core/test/terminate_handler_test.cpp Added manual test demonstrating terminate handler behavior
category/core/test/CMakeLists.txt Added build configuration for the manual test
category/core/CMakeLists.txt Registered new terminate handler source files
category/statesync/statesync_version.{h,cpp} Added noexcept to version API functions
category/statesync/statesync_server.{h,cpp} Added noexcept to server API functions
category/statesync/statesync_client.{h,cpp} Added noexcept to client API functions
category/rpc/eth_call.{h,cpp} Added noexcept to RPC API functions

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

@maxkozlovsky maxkozlovsky force-pushed the max/noexcept branch 7 times, most recently from 6ea6e50 to 65ab53c Compare November 4, 2025 21:07
Mark Rust ffi function as noexcept to prevent exception propagation to
Rust code. Any unhandled exceptions will result in direct call to
terminate().

This commit adds a custom terminate handler that provides detailed
diagnostics when std::terminate() is called. This helps debug issues
where exceptions escape noexcept functions or cross FFI boundaries.

The handler is installed via monad_set_terminate_handler() which
should be called early in main() before any exception-throwing code.

This code was generated using Claude Sonnet 4.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants