-
Notifications
You must be signed in to change notification settings - Fork 839
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 24 throw checked exception to remove todos #7481
5098 branch 24 throw checked exception to remove todos #7481
Conversation
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>
…-branch-2-update-invalid-accounts-params
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>
…-branch-2-update-invalid-accounts-params
…' 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>
…-branch-2-update-invalid-accounts-params
…' 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
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
…id-params' into 5098-branch-22-update-more-invalid-params
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
…_COMPLETE_TRANSACTION_PARAMS and update related messages 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>
…h a couple of missed catch clauses Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
...ue/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/methods/CliqueGetSigners.java
Outdated
Show resolved
Hide resolved
@@ -42,7 +43,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { | |||
final Hash hash; | |||
try { | |||
hash = requestContext.getRequiredParameter(0, Hash.class); | |||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException | |||
} catch (JsonRpcParameter.JsonRpcParameterException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be nicer to modify getRequiredParameter() to throw the ex
hash = requestContext.getRequiredParameterOrElseThrow(0, Hash.class, "Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS)
but there's a couple of spots where we do something different
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be another way to get the details we want into the exception, but in general, I'd prefer to keep low level code as simple as possible, and let higher level code handle the specifics in the appropriate context.
As a middle ground, I could implement a set of methods in JsonRpcRequestContext like
public Hash getRequiredHashParameter(int index)
which would clean up the higher level code, and still add detail to exceptions in the appropriate context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would simplify slightly - I have no strong opinion on that - will leave up to you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think given the length of time it would take, it's probably not worth doing right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice suggestion, it would make the code more readable removing a lot of try/catch blocks. but agree that it's probably not worth doing right now
@@ -60,11 +57,9 @@ public <T> T required(final Object[] params, final int index, final Class<T> par | |||
* @param <T> The type of parameter. | |||
* @return Returns the parameter cast as T if available. | |||
*/ | |||
// TODO: update to throw JsonRpcParameterException as a checked exception, forcing callers to | |||
// handle it to supply appropriate context | |||
@SuppressWarnings("unchecked") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this suppression be removed now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was unrelated to the changes I made. It seems we're retrieving an Object from the request context and performing an unchecked cast to a parameterized type. i.e.
final T param;
final Object rawParam = params[index];
if (paramClass.isAssignableFrom(rawParam.getClass())) {
// If we're dealing with a simple type, just cast the value
param = (T) rawParam;
}
Looks like even though we're checking the type of T is appropriate for the object, the compiler (or intelliJ) is still complaining about the unchecked cast. We can get around this by using paramClass.cast(rawParam)
, which should have the same effect.
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
…eption-to-remove-TODOs' into 5098-branch-24-throw-checked-exception-to-remove-TODOs
…ameter 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>
ethereum/stratum/src/main/java/org/hyperledger/besu/ethereum/stratum/Stratum1Protocol.java
Outdated
Show resolved
Hide resolved
@@ -42,7 +43,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { | |||
final Hash hash; | |||
try { | |||
hash = requestContext.getRequiredParameter(0, Hash.class); | |||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException | |||
} catch (JsonRpcParameter.JsonRpcParameterException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice suggestion, it would make the code more readable removing a lot of try/catch blocks. but agree that it's probably not worth doing right now
Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
) * 5098: Add RpcErrorTypes 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> Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com> Signed-off-by: Ade Lucas <ade.lucas@consensys.net>
) * 5098: Add RpcErrorTypes 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> Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com> Signed-off-by: gconnect <agatevureglory@gmail.com>
PR description
Final PR in the epic series of PRs. Throw checked exception at low level, and catch to remove TODOs. Also catch in a few places missed in previous reviews.
Fixed Issue(s)
#5098