Skip to content

fix: Issue 6787 catch all std::exception in getAsset (AMMInfo)#6845

Open
shortthefomo wants to merge 1 commit intoXRPLF:developfrom
shortthefomo:fix/6787-amminfo-catch-all-exceptions
Open

fix: Issue 6787 catch all std::exception in getAsset (AMMInfo)#6845
shortthefomo wants to merge 1 commit intoXRPLF:developfrom
shortthefomo:fix/6787-amminfo-catch-all-exceptions

Conversation

@shortthefomo
Copy link
Copy Markdown

High Level Overview of Change

Fix getAsset in the amm_info RPC handler catching only std::runtime_error from assetFromJson/issueFromJson, leaving Json::error and other std::exception subtypes uncaught. Such exceptions now propagate to the top-level callMethod handler and return an opaque rpcINTERNAL instead of the expected rpcISSUE_MALFORMED error.

Fixes #6787

Context of Change

Bug — present since getAsset (formerly getIssue) was introduced in AMMInfo.cpp.

assetFromJson delegates to issueFromJson, which throws Json::error (a subclass of std::exception, not std::runtime_error) for invalid currency or issuer string values — for example:

// issueFromJson throws Json::error here, not std::runtime_error:
Throw<Json::error>("issueFromJson currency must be a valid currency");
Throw<Json::error>("issueFromJson issuer must be a string Json value");

The original catch clause catch (std::runtime_error const& ex) did not cover these paths. Any Json::error thrown by issueFromJson would escape getAsset uncaught, propagate up through the RPC dispatch, be caught by the generic callMethod handler, and return rpcINTERNAL — a confusing error that gives the client no indication of the actual problem (a malformed asset field).

Fix: Widen the catch to catch (std::exception const& ex) so that all exception types thrown by assetFromJson/issueFromJson are handled locally and mapped to rpcISSUE_MALFORMED.

Before / After

Before — client sends amm_info with {"asset": {"currency": "!!!BAD!!!"}}:

{
  "result": {
    "error": "internal",
    "error_code": 73,
    "error_message": "Internal error.",
    "status": "error"
  }
}

After — same request returns the descriptive malformed-issue error:

{
  "result": {
    "error": "issueMalformed",
    "error_code": 46,
    "error_message": "Issue is malformed.",
    "status": "error"
  }
}

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

No API impact. The change only affects the error-path for malformed asset/asset2 inputs to amm_info; all well-formed requests are unaffected.

Test Plan

Added testGetAssetExceptionCoverage to AMMInfo_test.cpp. It sends an amm_info request with an asset field containing an invalid currency string ("!!!INVALID!!!") — the path that previously triggered Json::error and returned rpcINTERNAL. The test asserts:

  1. The response contains error (the request was correctly rejected).
  2. The error is not "internal" — confirming the exception is now caught locally and mapped to the correct error code rather than escaping to the generic handler.

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.

AMMInfo getIssue catches only std::runtime_error, not all exceptions from issueFromJson

1 participant