Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fc exception handling #980

Closed
heifner opened this issue Oct 28, 2024 · 1 comment · Fixed by #1031
Closed

fc exception handling #980

heifner opened this issue Oct 28, 2024 · 1 comment · Fixed by #1031
Assignees
Labels
👍 lgtm OCI Work exclusive to OCI team tech-debt

Comments

@heifner
Copy link
Member

heifner commented Oct 28, 2024

fc::exception has support for dynamic_rethrow_exception which is documented as:

   /**
    * Rethrows the exception restoring the proper type based upon
    * the error code.  This is used to propagate exception types
    * across conversions to/from JSON
    */

We use this in a few places:

std::get<fc::exception_ptr>(result)->dynamic_rethrow_exception(); \

std::get<fc::exception_ptr>(result)->dynamic_rethrow_exception();

This requires:

FC_REGISTER_EXCEPTIONS( (timeout_exception)
(file_not_found_exception)
(parse_error_exception)
(invalid_arg_exception)
(invalid_operation_exception)
(key_not_found_exception)
(bad_cast_exception)
(out_of_range_exception)
(canceled_exception)
(assert_exception)
(eof_exception)
(unknown_host_exception)
(null_optional)
(udt_exception)
(aes_exception)
(overflow_exception)
(underflow_exception)
(divide_by_zero_exception)
)

Which we do NOT do for any of the chain exceptions in:

FC_DECLARE_DERIVED_EXCEPTION( chain_type_exception, chain_exception,

Note we add an error_code to chain_exception which all chain exceptions derive from. This is used here:

std::optional<uint64_t> controller::convert_exception_to_error_code( const fc::exception& e ) {
const chain_exception* e_ptr = dynamic_cast<const chain_exception*>( &e );
if( e_ptr == nullptr ) return {};
if( !e_ptr->error_code ) return static_cast<uint64_t>(system_error_code::generic_system_error);
return e_ptr->error_code;
}

But even if we did register them, they would slice off the error_code on rethrow:

virtual NO_RETURN void rethrow( const exception& e )const override
{
throw T( e );
}

When exceptions are placed action_trace and transaction_trace they are sliced to a fc::exception losing this error_code:

std::optional<fc::exception> except;

When an exception is placed in the action_trace or transaction_trace and is rethrown, it is always rethrown as a fc::exception. As commented here:

// this always throws an fc::exception, since the original exception is copied into an fc::exception
trace->except->dynamic_rethrow_exception();

Changing action_trace and transaction_trace to use an fc::exception_ptr is an API breaking change.
Changing fc::exception to have an error_code is also an API breaking change. Since this is an addition, maybe this would cause no harm. Not sure if that affects consensus.

@bhazzard
Copy link

bhazzard commented Nov 7, 2024

Plan for 1.1.0 is to avoid breaking change in API, and remove dynamic-rethrow-exception

@bhazzard bhazzard added this to the Spring v1.1.0-rc1 milestone Nov 7, 2024
@bhazzard bhazzard added 👍 lgtm and removed triage labels Nov 7, 2024
@heifner heifner self-assigned this Nov 14, 2024
@heifner heifner added the OCI Work exclusive to OCI team label Nov 14, 2024
@heifner heifner moved this from Todo to In Progress in Team Backlog Nov 14, 2024
@heifner heifner moved this from In Progress to Awaiting Review in Team Backlog Nov 14, 2024
heifner added a commit that referenced this issue Nov 15, 2024
Remove fc dynamic_rethrow_exception
@github-project-automation github-project-automation bot moved this from Awaiting Review to Done in Team Backlog Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👍 lgtm OCI Work exclusive to OCI team tech-debt
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants