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

SpotlessKotlin error output is missing line numbers #249

Closed
runningcode opened this issue May 23, 2018 · 4 comments · Fixed by #251
Closed

SpotlessKotlin error output is missing line numbers #249

runningcode opened this issue May 23, 2018 · 4 comments · Fixed by #251

Comments

@runningcode
Copy link
Contributor

When spotlessKotlin fails it ouputs a large stacktrace which makes it hard to figure out which line number failed.

It would be nice to have an output similar to the spotlessJava task but at the very least to include the line numbers where the task failed.

Here is an example stacktrace from a failed kotlin task.

> Task :app:spotlessKotlin FAILED
Step 'ktlint' found problem in 'app/src/main/java/com/foo/bar/Foo.kt':
Unexpected indentation (17) (it should be 16)
java.lang.AssertionError: Unexpected indentation (17) (it should be 16)
        at com.diffplug.spotless.kotlin.KtLintStep$State.lambda$createFormat$0(KtLintStep.java:110)
        at com.sun.proxy.$Proxy115.invoke(Unknown Source)
        at com.github.shyiko.ktlint.core.KtLint$format$2$1.invoke(KtLint.kt:357)
        at com.github.shyiko.ktlint.core.KtLint$format$2$1.invoke(KtLint.kt:36)
        at com.github.shyiko.ktlint.ruleset.standard.IndentationRule.visit(IndentationRule.kt:41)
        at com.github.shyiko.ktlint.core.KtLint$format$2.invoke(KtLint.kt:355)
        at com.github.shyiko.ktlint.core.KtLint$format$2.invoke(KtLint.kt:36)
        at com.github.shyiko.ktlint.core.KtLint$visitor$2$1.invoke(KtLint.kt:201)
        at com.github.shyiko.ktlint.core.KtLint$visitor$2$1.invoke(KtLint.kt:36)
        at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:487)
        at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:488)
        at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:488)
        at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:488)
        at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:488)
        at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:488)
        at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:488)
        at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:488)
        at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:488)
        at com.github.shyiko.ktlint.core.KtLint.visit(KtLint.kt:488)
        at com.github.shyiko.ktlint.core.KtLint.access$visit(KtLint.kt:36)
        at com.github.shyiko.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:199)
        at com.github.shyiko.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:36)
        at com.github.shyiko.ktlint.core.KtLint.format(KtLint.kt:350)
        at com.github.shyiko.ktlint.core.KtLint.format(KtLint.kt:279)
        at sun.reflect.GeneratedMethodAccessor136.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.diffplug.spotless.kotlin.KtLintStep$State.lambda$createFormat$1(KtLintStep.java:124)
        at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:78)
        at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:76)
        at com.diffplug.spotless.Formatter.compute(Formatter.java:230)
        at com.diffplug.spotless.Formatter.isClean(Formatter.java:167)
        at com.diffplug.gradle.spotless.SpotlessTask.check(SpotlessTask.java:263)
        at com.diffplug.gradle.spotless.SpotlessTask.performAction(SpotlessTask.java:205)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:124)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
...

I would be happy to work on this but I'm not quite sure what the best way to format the output would be. I see that this exception is thrown on KtLintStep.java:110 and that the LintError object includes the line and column number.

Is there a better way to throw the exception other than AssertionError?

@nedtwigg
Copy link
Member

You can throw any subclass of Error, doesn't have to be AssertionError.

@runningcode
Copy link
Contributor Author

Cool. I'm a bit confused as how the mechanism that groups errors using DiffMessageFormatter works. It seems to work for java based errors but not kotlin errors. Is there a reason why?

@nedtwigg
Copy link
Member

There's two kinds of formatter:

  1. Function<String, String> , which can fix the error itself
  2. Consumer<String> throws Error, which can't fix the error, it just throws an exception saying "this is bad!"

Spotless is built around (1), because it's the kind of fix which is easy for users to deal with. Those work with DiffMessageFormatter, which shows the diff that would be applied if you called spotlessApply.

Spotless also supports (2), but it's not possible to do as much with it, because all we have to work with is an error, there's no suggested fix.

runningcode pushed a commit to runningcode/spotless that referenced this issue May 29, 2018
runningcode pushed a commit to runningcode/spotless that referenced this issue May 30, 2018
runningcode pushed a commit to runningcode/spotless that referenced this issue May 30, 2018
@nedtwigg
Copy link
Member

nedtwigg commented Jun 2, 2018

Released in 3.13.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants