-
Notifications
You must be signed in to change notification settings - Fork 185
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
Add a message error to scalafixFileEvaluation #1251
Conversation
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.
Makes sense! A few comments regarding the API changes.
@@ -104,6 +104,7 @@ object MainOps { | |||
val files = getFilesFrom(args) | |||
val fileEvaluations = { | |||
files.map { file => | |||
println(s"file = ${file}") |
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.
println(s"file = ${file}") |
@@ -22,6 +22,8 @@ | |||
*/ | |||
boolean isSuccessful(); | |||
|
|||
Optional<String> getMessageError(); |
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.
could you add some javadoc? does "error" include lint errors?
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.
ok. It includes lintErrors.
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.
sorry if I wasn't clear but I was talking about getMessageError
- I think the getErrors
are clear enough given their signature so the javadoc there is redundant.
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.
Actually this message error won't be empty except if the error is
case _: ParseException =>
case _: SemanticDocument.Error.MissingSemanticdb =>
case _: StaleSemanticDB =>
case NonFatal(_) =>
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.
and messageError do not include lint errors. LinterError are described in diagnostics
scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixEvaluation.java
Outdated
Show resolved
Hide resolved
e1edab8
to
837652b
Compare
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.
Looks good! Just one question: is scalafix-interfaces/.DS_Store
added on purpose? Not sure what that file does.
val evaluation2 = args.evaluate() | ||
assert(evaluation2.getErrors.head.toString == "StaleSemanticdbError") | ||
assert(evaluation2.getMessageError == Optional.empty()) | ||
assert(!evaluation2.isSuccessful) | ||
val fileEval = evaluation2.getFileEvaluations.head | ||
assert(fileEval.getErrors.head.toString == "StaleSemanticdbError") | ||
assert(fileEval.getMessageError.get.startsWith("Stale SemanticDB")) |
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.
👍 can we cover the other isSuccessful
while we are at it?
val evaluation2 = args.evaluate() | |
assert(evaluation2.getErrors.head.toString == "StaleSemanticdbError") | |
assert(evaluation2.getMessageError == Optional.empty()) | |
assert(!evaluation2.isSuccessful) | |
val fileEval = evaluation2.getFileEvaluations.head | |
assert(fileEval.getErrors.head.toString == "StaleSemanticdbError") | |
assert(fileEval.getMessageError.get.startsWith("Stale SemanticDB")) | |
val evaluation2 = args.evaluate() | |
assert(evaluation2.getErrors.head.toString == "StaleSemanticdbError") | |
assert(evaluation2.getMessageError == Optional.empty()) | |
assert(!evaluation2.isSuccessful) | |
val fileEval = evaluation2.getFileEvaluations.head | |
assert(fileEval.getErrors.head.toString == "StaleSemanticdbError") | |
assert(fileEval.getMessageError.get.startsWith("Stale SemanticDB")) | |
assert(!fileEval.isSuccessful) |
override def getErrors: Array[ScalafixError] = { | ||
ScalafixErrorImpl.fromScala(error) | ||
} | ||
override def isSuccessful: Boolean = | ||
getErrors.toList.filter(_ != ScalafixError.LinterError).isEmpty |
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 the behavior change of both isSuccessful
is lacking a test case to prevent regressions
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.
ok, good idea
1522445
to
c80fcb9
Compare
LinterErrors were only added at the end, when scalafixFileEvaluations contain nonEmpty diagnostics (through adjustExitCode). I did a choice to concatenate all scalafixFileEval error messages if scalafix has run successfully only on a number of files. Just a suggestion |
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 am afraid I am still having a hard time figuring out the behavior by looking at the docs. I think the problem comes from the re-use of the enum ScalafixError
.
This API is brand new, maybe it's still time to deprecate getErrorMessage
(which concatenates errors in a way that makes it hard to consume for a non-human) & getErrors
which have a similar signature in ScalafixEvaluation
and ScalafixFileEvaluation
, yet different possible values.
What about replacing them with ScalafixEvaluationError[] getEvaluationErrors()
, ScalafixEvaluationError
being an interface with a getType
returning an enum with only "operational errors" (maybe only the ones specific to the whole invocation, no need to aggregate the ones from files?), and getMessage
? Same thing for ScalafixFileEvaluationError
, with its own embedded enum. It sounds like a lot of changes, but it would avoid a lot of ambiguous documentation and testing.
* @return a more detailed error message that can be | ||
* - an explanation of why scalafix failed running at all | ||
* - a concatenation of all {@Link ScalafixFileEvaluation} message Errors |
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.
Cosmetic, but I think you need tags for this list of bullet points to appear properly in Javadoc like https://javadoc.io/doc/ch.epfl.scala/scalafix-interfaces/0.9.21/scalafix/interfaces/ScalafixFileEvaluation.html. Have a look at the rest of the Javadoc, it's very clean, so I think we should try to keep the same standard.
* @return a more detailed error in case of scalafix ParseError, StaleSemanticdbError, | ||
* MissingSemanticdbError or an UnexpectedError. LinterErrors are found in {@link ScalafixDiagnostic} |
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 am not in front of an IDE, but looking at the code, it looks like the error message is only defined for UnexpectedError
.
scalafix/scalafix-cli/src/main/scala/scalafix/internal/v1/MainOps.scala
Lines 122 to 125 in e31e5c9
case Failure(exception) => | |
ScalafixFileEvaluationImpl | |
.from(file, ExitStatus.UnexpectedError, exception.getMessage)( | |
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.
true, but this has been fixed in this PR.
case Failure(exception) =>
.from(file, ExitStatus.from(exception), exception.getMessage)
...
def from(throwable: Throwable): (ExitStatus) =
throwable match {
case _: ParseException =>
ExitStatus.ParseError
case _: SemanticDocument.Error.MissingSemanticdb =>
ExitStatus.MissingSemanticdbError
case _: StaleSemanticDB =>
ExitStatus.StaleSemanticdbError
case NonFatal(_) =>
ExitStatus.UnexpectedError
}
*/ | ||
boolean isSuccessful(); | ||
|
||
ScalafixError[] getErrors(); | ||
|
||
/** | ||
* | ||
* @return a more detailed error message that can be |
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.
more than what?
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 error , wchich is only the type of the Enum
scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixEvaluation.java
Outdated
Show resolved
Hide resolved
scalafix-cli/src/main/scala/scalafix/internal/interfaces/ScalafixFileEvaluationImpl.scala
Show resolved
Hide resolved
I agree. It will be easier to add new |
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.
Much clearer with new enums! A last round of comments about the behavior and a clearer javadoc, and I guess we are good to go!
scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixFileEvaluation.java
Outdated
Show resolved
Hide resolved
scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixFileEvaluation.java
Outdated
Show resolved
Hide resolved
scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixEvaluation.java
Outdated
Show resolved
Hide resolved
scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixEvaluation.java
Outdated
Show resolved
Hide resolved
scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixFileEvaluation.java
Outdated
Show resolved
Hide resolved
scalafix-interfaces/src/main/java/scalafix/interfaces/EvaluationError.java
Outdated
Show resolved
Hide resolved
(rebase needed) |
* Modify isSuccessful of ScalafixEvaluation: If a lintError is found, isSuccessful is false. A LintError is produced when scalafix has run successfully and there are diagnostics with severity Error. The issue is the default severity is Error, and rules don't usually modify that. I think it's misleading to report that scalafix has failed, when there are diagnostics. * Fix the reporting of StaleSemanticDB error. We were reporting unexpected Error instead of StaleSemanticdbError
* fix javadoc * keep the same behavior for isSuccesful for scalafixFileEvaluation
…calafixEvaluation - Deprecate old methods to retrieve errors in ScalafixEvaluation and ScalafixFileEvaluation
Thanks for your review. I addressed all your comments. |
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.
👍
Modify isSuccessful of ScalafixEvaluation: If a lintError is found, isSuccessful is false.
A LintError is produced when scalafix has run successfully and there are diagnostics with severity Error.
The issue is the default severity is Error, and rules don't usually modify that.
I think it's misleading to report that scalafix has failed, when there are diagnostics.
Fix the reporting of StaleSemanticDB error. We were reporting unexpected Error instead of StaleSemanticdbError