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

Ktfmt failed to run with... #72

Closed
brizzbuzz opened this issue May 21, 2022 · 10 comments
Closed

Ktfmt failed to run with... #72

brizzbuzz opened this issue May 21, 2022 · 10 comments

Comments

@brizzbuzz
Copy link

🐛 Describe the bug

👋 Neat plugin... was excited to give it a spin, unfortunately I'm running into a problem that I'm not sure how to triage further. I have applied the ktfmt plugin to my project modules, but when I run ./gradlew ktfmtFormat it spits out a bunch of e: Generic error during file processing messages. Digging a bit deeper with ./gradewl ktfmtFormat --stacktrace I get the following

Caused by: java.lang.IllegalStateException: Ktfmt failed to run with 18 failures
        at com.ncorti.ktfmt.gradle.tasks.KtfmtFormatTask.execute$suspendImpl(KtfmtFormatTask.kt:42)
        at com.ncorti.ktfmt.gradle.tasks.KtfmtFormatTask$execute$1.invokeSuspend(KtfmtFormatTask.kt)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:39)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

Which is still... not super helpful? I'm not sure what the 18 failures are 🤷

⚠️ Current behavior

Cannot run ktfmt

✅ Expected behavior

Can run ktfmt

💣 Steps to reproduce

Bit hard to say given how unspecific the error messages are 😔

📷 Screenshots

N/A

📱 Tech info

  • Device: M1 Mac
  • OS: Monterey
  • Gradle: 7.4.2
  • Kotlin: 1.6.21
  • Ktfmt Plugin: 0.8.0
@cortinico
Copy link
Owner

Can you provide a full build log?
When that Ktfmt failed to run with 18 failures happens, the build should also output the files where the failures happened with something like: Failed to analyse: ...

If you could rerun also with:

./gradewl ktfmtFormat --info --scan --stacktrace

would be really helpful for me to debug

@brizzbuzz
Copy link
Author

https://scans.gradle.com/s/5wteeksr5wilc

It does output the files, if poking at the source code would help you can find it all here on this branch https://github.com/bkbnio/kompendium/tree/v3

@brizzbuzz
Copy link
Author

ahh i think I see the problem... the list of files that break ktfmt are effectively fully commented out 😄 This branch is a practically a total re-write of the library, so a number of files are currently totally commented out (see here).

@brizzbuzz
Copy link
Author

Oh nevermind, that was just for that particular module..... if I apply it to another module with actual code, it still explodes :(

@cortinico
Copy link
Owner

So that error (Failed to analyse) happens if the file is not a valid Kotlin file.
Also this could probably be reported on the KtFmt Repo.

if I apply it to another module with actual code, it still explodes :(

Could you link which file you're referring to?
Like could you provide an example of a file which is failing to format and you would not expect instead? I'd love to see the content

@brizzbuzz
Copy link
Author

If you wanna replicate, I've gone ahead and created a ktfmt branch here. If you clone that and run ./gradlew ktfmtCheck --continue it will dump out the errors for every module. It looks like every single module fails... maybe even on every single file? I was too lazy to verify that... but it's a lot of them

@brizzbuzz
Copy link
Author

went ahead and pushed that via the gradle scan thingy as well https://scans.gradle.com/s/dg6pvfjsqbnta

@cortinico
Copy link
Owner

Thanks for the reproducer, that helped me replicate. For some reason the plugin is failing with this stacktrace:

java.lang.NoClassDefFoundError: Could not initialize class com.facebook.ktfmt.format.Parser
        at com.facebook.ktfmt.format.Formatter.sortedAndDistinctImports(Formatter.kt:141)
        at com.facebook.ktfmt.format.Formatter.format(Formatter.kt:84)
        at com.ncorti.ktfmt.gradle.tasks.KtfmtBaseTask.processFile$plugin(KtfmtBaseTask.kt:103)
        at com.ncorti.ktfmt.gradle.tasks.KtfmtBaseTask$processFileCollection$2$1.invokeSuspend(KtfmtBaseTask.kt:120)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)

It seems like it's failing inside ktfmt, and not inside the Gralde plugin. I'll have to take a closer look and get back to you.

@cortinico
Copy link
Owner

So I looked into this @unredundant and the problem seems to be inside the plugin you're using:

https://github.com/bkbnio/sourdough-gradle/blob/main/library-jvm/src/main/kotlin/io/bkbn/sourdough/gradle/library/jvm/LibraryJvmPlugin.kt

I don't know what the exact reason is as this plugin is essentially configuring a lot of things. As soon as you remove it from your setup, ktfmt-gradle works correctly.
I suspect is the toolchain version configured by them which causes this NoClassDefFoundError but I'm not entirely sure.

I would advice against using those kind of plugins which encapsulate "too much" and creates those sort of errors.

Anyway, this issue should probably be raised against them.

@brizzbuzz
Copy link
Author

Oh super interesting! I maintain that plugin as well, it's pretty much just meant to keep my gradle configs DRY.

Thanks for looking into this, I'll close this since it's just some incompatibility with my own work :)

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

No branches or pull requests

2 participants