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

5098 branch 4 update invalid address params #7405

Conversation

Matilda-Clerke
Copy link
Contributor

PR description

Update code to use RpcErrorType.INVALID_ADDRESS_PARAMS

Fixed Issue(s)

#5098

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
…ion, apply spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
…ion, apply spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
…' into 5098-branch-3-update-invalid-address-hash-params
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
…' into 5098-branch-3-update-invalid-address-hash-params
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
…' into 5098-branch-3-update-invalid-address-hash-params
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
…ounts-params' into 5098-branch-2-update-invalid-accounts-params
…' into 5098-branch-3-update-invalid-address-hash-params
…rams' into 5098-branch-4-update-invalid-address-params
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
…' into 5098-branch-3-update-invalid-address-hash-params
…rams' into 5098-branch-4-update-invalid-address-params
address = requestContext.getRequiredParameter(0, Address.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid address parameter", RpcErrorType.INVALID_ADDRESS_PARAMS, e);
Copy link
Contributor

@siladu siladu Jul 31, 2024

Choose a reason for hiding this comment

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

IIUC, there's two messages related to this error:

  1. The string here: "Invalid address parameter"
  2. The one hardcoded against INVALID_ADDESS_PARAMS (added the previous PR):
    "Invalid address params"

Why do we need both and is there a reason we need all the extra RpcErrorTypes versus dynamically passing the string here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are times when the message can add some extra context, but for the most part it's redundant.

Copy link
Contributor

Choose a reason for hiding this comment

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

So how does this work, does one override the other or does it respond with both?
Have you got an example where the message gives extra context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I don't really know the full context of how each message is used and where.

Copy link
Contributor

Choose a reason for hiding this comment

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

Updating for completeness...we figured out that this error message is displaying in a DEBUG log stack, whereas the one attached to INVALID_ADDRESS_PARAMS is what the user actually sees. At least in the example tested.

@@ -121,7 +121,7 @@ public void discardWithoutAddress() {
final Discard discard = new Discard(validatorProvider);

assertThatThrownBy(() -> discard.response(requestWithParams()))
.hasMessage("Missing required json rpc parameter at index 0")
.hasMessage("Invalid address parameter")
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if also knowing the parameter index could be useful for users in any of these RPC error? e.g. if you have multiple parameters with values that either are or could look like an Address (i.e. a hash)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, could be useful yeah. I'll update for this PR and we can assess whether we want to apply it across all of the PRs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@siladu Feel free to take another look now that I've updated the exception messages. Do you think we should apply this across the board?

macfarla and others added 3 commits August 1, 2024 06:33
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Copy link
Contributor

@siladu siladu left a comment

Choose a reason for hiding this comment

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

LGTM

@Matilda-Clerke Matilda-Clerke merged commit e3bc248 into hyperledger:main Aug 2, 2024
40 checks passed
gconnect pushed a commit to gconnect/besu that referenced this pull request Aug 26, 2024
* 5098: Add RpcErrorTypes

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Modify InvalidJsonRpcParameters and InvalidJsonRpcRequestException, apply spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Modify InvalidJsonRpcParameters and InvalidJsonRpcRequestException, apply spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Add JsonRpcParameterException for later use

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Update locations for RpcErrorType.INVALID_ACCOUNTS_PARAMS

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Address review comments, apply spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Update with changes from branch 1

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Update code to use RpcErrorType.INVALID_ADDRESS_HASH_PARAMS

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: apply spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: apply spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Update plugin-api gradle hash

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Add comment on INVALID_PARAMS_ERROR_CODE

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Apply spotless on latest changes

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Update code to use RpcErrorType.INVALID_ADDRESS_PARAMS

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Fix broken unit test

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Fix broken unit test

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Add index to exception messages

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: apoply spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 5098: Update BaseJsonRpcProcessor to utilise RpcErrorType from InvalidJsonRpcParameters

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

---------

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: gconnect <agatevureglory@gmail.com>
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