-
Notifications
You must be signed in to change notification settings - Fork 395
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
[#1745] improvement(api): Add errorprone plugin to format exception message #1746
Conversation
8f31b5a
to
3cc2761
Compare
@coolderli , Thanks for your contribution, can you provide the effection this PRs introduces? |
@yuqi1129 When concating the message of exception, we have to use
In this PR, we can format the message like this:
We have already done this on RESTException But the annotation |
@yuqi1129 what do you think about this change? It's just a code refactor. |
Is this https://github.com/tbroyer/gradle-errorprone-plugin |
@yuqi1129 Yes. I already tried to test this plugin but failed to make it work. I need to try again when I have time. Do we really need this plugin? What about I remove the annotation |
I believe the optimization is effective and meaningful, but it should work with the plugin. Can you spare some time to test the plugins? |
Ok, I got it. I will try my best. |
We definitely need this, this is a good improvement. @coolderli can you please continue your work when you have time. |
86bed67
to
2a8ae96
Compare
build.gradle.kts
Outdated
options.errorprone.isEnabled.set(true) | ||
options.errorprone.disableAllChecks.set(true) | ||
options.errorprone.enable( | ||
"AnnotateFormatMethod" |
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.
Only enable @FormatMethod
, because we enable -Werror
, Or there are a lot of warnings that are treated as an error.
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.
good improvement!I had the same problem last night.
67877e7
to
36b8c68
Compare
@@ -15,21 +15,22 @@ | |||
/** Exception converter to gravitino exception for MySQL. */ | |||
public class MysqlExceptionConverter extends JdbcExceptionConverter { | |||
|
|||
@SuppressWarnings("FormatStringAnnotation") |
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.
The string that is annotationed by @FormatString
must be a final string or a compile time constant value. a variable is not allowed, such as
new NoSuchEntityException(se.getMessage)
So I just ignore it by @SuppressWarnings("FormatStringAnnotation")
@@ -287,13 +285,13 @@ public <E extends Entity & HasIdentifier> E get( | |||
() -> { | |||
byte[] key = entityKeyEncoder.encode(ident, entityType, true); | |||
if (key == null) { | |||
throw new NoSuchEntityException(ident.toString()); | |||
throw new NoSuchEntityException("No such entity:%s", ident.toString()); |
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.
Another fix is like this. We use the format string.
@@ -34,6 +35,7 @@ | |||
* <p>Referred from spark/v3.4/spark/src/test/java/org/apache/iceberg/spark/SparkTestBase.java | |||
*/ | |||
|
|||
@SuppressWarnings("FormatStringAnnotation") |
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.
Too many changes, just ignore them.
public GravitinoRuntimeException(String message, Throwable cause) { | ||
super(message, cause); | ||
@FormatMethod | ||
public GravitinoRuntimeException(Throwable cause, @FormatString String message, Object... args) { |
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.
The Throwable
must be the first argument. Or it will throw an exception. I think it is conflict with the variable parameters in the overloaded function
@FormatMethod
public GravitinoRuntimeException(@FormatString String message, Object... args) {
super(String.format(message, args));
}
@@ -115,6 +117,7 @@ private void stopSparkEnv() { | |||
} | |||
} | |||
|
|||
@FormatMethod |
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.
If a method uses string.format()
, it must be annotated by @FormatMethod
, or there will be an error.
If there are some format problems, some errors will be thrown like below:
|
@jerryshao @yuqi1129 Finally, I finished this. Please take a review when you have time. Thanks. |
Thank you for your hard work, we will review it soon. |
If it helps (and I've not gone through them all) these checks that currently pass:
So you could enable all of these And these ones (and probably more) currently fail:
Which we can raise as separate issues. |
Thanks for your reply.Because we enabled -Weeror.If I enabled all check ,I have to fix all of them in this PR. I |
Yes, we can fix these in another issue. I've already raised some issues for them. |
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.
LGTM - thanks for all your work on this
What changes were proposed in this pull request?
close #1745
Format exception message by String.format
Why are the changes needed?
Format the message of exception for better coding
Fix: #1745
Does this PR introduce any user-facing change?
How was this patch tested?