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

Add a message error to scalafixFileEvaluation #1251

Merged
merged 5 commits into from
Oct 27, 2020

Conversation

mlachkar
Copy link
Collaborator

@mlachkar mlachkar commented Oct 5, 2020

  • 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

@mlachkar mlachkar linked an issue Oct 5, 2020 that may be closed by this pull request
@mlachkar mlachkar requested review from bjaglin and tgodzik October 5, 2020 11:00
Copy link
Collaborator

@bjaglin bjaglin left a 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}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
println(s"file = ${file}")

@@ -22,6 +22,8 @@
*/
boolean isSuccessful();

Optional<String> getMessageError();
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok. It includes lintErrors.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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(_) =>

Copy link
Collaborator Author

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

@mlachkar mlachkar force-pushed the errors branch 2 times, most recently from e1edab8 to 837652b Compare October 5, 2020 13:11
Copy link
Contributor

@tgodzik tgodzik left a 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.

Comment on lines 177 to 186
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"))
Copy link
Collaborator

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?

Suggested change
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
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, good idea

@mlachkar mlachkar force-pushed the errors branch 3 times, most recently from 1522445 to c80fcb9 Compare October 7, 2020 16:31
@mlachkar
Copy link
Collaborator Author

mlachkar commented Oct 7, 2020

LinterErrors were only added at the end, when scalafixFileEvaluations contain nonEmpty diagnostics (through adjustExitCode).
ScalafixEvaluation is a new api, that is not meant to be used as a cli, and only thought code calls. LinterErrors are already represented as a ScalafixDiagnostics.
The last commit removes the adjustExitCode, so we don't need anymore to filter LinterErrors from errors, when verifying isSuccessful.

I did a choice to concatenate all scalafixFileEval error messages if scalafix has run successfully only on a number of files. Just a suggestion

Copy link
Collaborator

@bjaglin bjaglin left a 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.

Comment on lines 15 to 17
* @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
Copy link
Collaborator

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.

Comment on lines 27 to 28
* @return a more detailed error in case of scalafix ParseError, StaleSemanticdbError,
* MissingSemanticdbError or an UnexpectedError. LinterErrors are found in {@link ScalafixDiagnostic}
Copy link
Collaborator

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.

case Failure(exception) =>
ScalafixFileEvaluationImpl
.from(file, ExitStatus.UnexpectedError, exception.getMessage)(
args

Copy link
Collaborator Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

more than what?

Copy link
Collaborator Author

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

@mlachkar
Copy link
Collaborator Author

mlachkar commented Oct 8, 2020

I agree. It will be easier to add new ScalafixErrors. I will rework this. Thanks
The getErrorMessage doesn't need to be a concatenation. it can be just error message in case of scalafix not running at all.
And we can keep errror message of file, in ScalafixFileEvaluation part

@mlachkar mlachkar requested a review from bjaglin October 26, 2020 15:27
Copy link
Collaborator

@bjaglin bjaglin left a 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!

@bjaglin
Copy link
Collaborator

bjaglin commented Oct 27, 2020

(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
@mlachkar
Copy link
Collaborator Author

Thanks for your review. I addressed all your comments.

@mlachkar mlachkar requested a review from bjaglin October 27, 2020 08:17
Copy link
Collaborator

@bjaglin bjaglin left a comment

Choose a reason for hiding this comment

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

👍

@mlachkar mlachkar merged commit 1ea958e into scalacenter:master Oct 27, 2020
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.

Error message not exposed in the API
3 participants