zalando / intellij-swagger

A plugin to help you easily edit Swagger and OpenAPI specification files inside IntelliJ IDEA
https://plugins.jetbrains.com/plugin/8347
MIT License
1.18k stars 75 forks source link

Cannot obtain text for binary file type : UNKNOWN #69

Closed ddska closed 7 years ago

ddska commented 7 years ago

Got this error in the IDEA while in the Go lang project:

To reindex this file IDEA has to be restarted: Cannot obtain text for binary file type : UNKNOWN
com.intellij.util.indexing.FileContentImpl$IllegalDataException: Cannot obtain text for binary file type : UNKNOWN
    at com.intellij.util.indexing.FileContentImpl.getContentAsText(FileContentImpl.java:218)
    at com.intellij.util.indexing.FileContentImpl.getPsiFile(FileContentImpl.java:80)
    at org.zalando.intellij.swagger.index.SwaggerDataIndexer.map(SwaggerDataIndexer.java:39)
    at org.zalando.intellij.swagger.index.SwaggerDataIndexer.map(SwaggerDataIndexer.java:28)
    at com.intellij.util.indexing.MapReduceIndex.update(MapReduceIndex.java:461)
    at com.intellij.util.indexing.FileBasedIndexImpl.a(FileBasedIndexImpl.java:1631)
    at com.intellij.util.indexing.FileBasedIndexImpl.a(FileBasedIndexImpl.java:1567)
    at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.freezeFileTypeTemporarilyIn(FileTypeManagerImpl.java:507)
    at com.intellij.util.indexing.FileBasedIndexImpl.a(FileBasedIndexImpl.java:1528)
    at com.intellij.util.indexing.FileBasedIndexImpl.indexFileContent(FileBasedIndexImpl.java:1513)
    at com.intellij.util.indexing.FileBasedIndexImpl.processRefreshedFile(FileBasedIndexImpl.java:1493)
    at com.intellij.util.indexing.FileBasedIndexProjectHandler.a(FileBasedIndexProjectHandler.java:157)
    at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.a(CacheUpdateRunner.java:235)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1061)
    at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.a(CacheUpdateRunner.java:252)
    at com.intellij.openapi.progress.impl.CoreProgressManager$3.run(CoreProgressManager.java:179)
    at com.intellij.openapi.progress.impl.CoreProgressManager.a(CoreProgressManager.java:568)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:519)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:164)
    at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.run(CacheUpdateRunner.java:248)
    at com.intellij.openapi.application.impl.ApplicationImpl$2.run(ApplicationImpl.java:309)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Swagger plugin version: 0.0.26 Ubuntu 16.10 IntelliJ IDEA 2016.3.3 Build #IU-163.11103.6, built on January 16, 2017 JRE: 1.8.0_112-release-408-b6 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

semonte commented 7 years ago

@ddska Thanks for the report. Are you able to share the project that is causing this error?

ddska commented 7 years ago

Unfortunately, no. But the error happened while indexing this file: https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/eccc4ee97c6d6a2a52326870e1b6710320e65148/Godeps/_workspace/src/gopkg.in/yaml.v2/LICENSE.libyaml

ddska commented 7 years ago

Got this error again, on different project, now with Gogland IDE, Swagger plugin version 0.0.27:

Error while indexing /home/dds/dev/go/vendor/github.com/docker/distribution/vendor/gopkg.in/yaml.v2/LICENSE.libyaml
To reindex this file IDEA has to be restarted: Cannot obtain text for binary file type : UNKNOWN
com.intellij.util.indexing.FileContentImpl$IllegalDataException: Cannot obtain text for binary file type : UNKNOWN
    at com.intellij.util.indexing.FileContentImpl.getContentAsText(FileContentImpl.java:218)
    at com.intellij.util.indexing.FileContentImpl.getPsiFile(FileContentImpl.java:80)
    at org.zalando.intellij.swagger.index.SwaggerDataIndexer.map(SwaggerDataIndexer.java:39)
    at org.zalando.intellij.swagger.index.SwaggerDataIndexer.map(SwaggerDataIndexer.java:28)
    at com.intellij.util.indexing.MapReduceIndex.update(MapReduceIndex.java:461)
    at com.intellij.util.indexing.FileBasedIndexImpl.a(FileBasedIndexImpl.java:1631)
    at com.intellij.util.indexing.FileBasedIndexImpl.a(FileBasedIndexImpl.java:1567)
    at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.freezeFileTypeTemporarilyIn(FileTypeManagerImpl.java:507)
    at com.intellij.util.indexing.FileBasedIndexImpl.a(FileBasedIndexImpl.java:1528)
    at com.intellij.util.indexing.FileBasedIndexImpl.indexFileContent(FileBasedIndexImpl.java:1513)
    at com.intellij.util.indexing.FileBasedIndexImpl.processRefreshedFile(FileBasedIndexImpl.java:1493)
    at com.intellij.util.indexing.FileBasedIndexProjectHandler.a(FileBasedIndexProjectHandler.java:157)
    at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.a(CacheUpdateRunner.java:235)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1061)
    at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.a(CacheUpdateRunner.java:252)
    at com.intellij.openapi.progress.impl.CoreProgressManager$3.run(CoreProgressManager.java:179)
    at com.intellij.openapi.progress.impl.CoreProgressManager.a(CoreProgressManager.java:568)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:519)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:164)
    at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.run(CacheUpdateRunner.java:248)
    at com.intellij.openapi.application.impl.ApplicationImpl$2.run(ApplicationImpl.java:309)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

com.intellij.util.indexing.FileContentImpl$IllegalDataException: Cannot obtain text for binary file type : UNKNOWN
    at com.intellij.util.indexing.FileContentImpl.getContentAsText(FileContentImpl.java:218)
    at com.intellij.util.indexing.FileContentImpl.getPsiFile(FileContentImpl.java:80)
    at org.zalando.intellij.swagger.index.SwaggerDataIndexer.map(SwaggerDataIndexer.java:39)
    at org.zalando.intellij.swagger.index.SwaggerDataIndexer.map(SwaggerDataIndexer.java:28)
    at com.intellij.util.indexing.MapReduceIndex.update(MapReduceIndex.java:461)
    at com.intellij.util.indexing.FileBasedIndexImpl.a(FileBasedIndexImpl.java:1631)
    at com.intellij.util.indexing.FileBasedIndexImpl.a(FileBasedIndexImpl.java:1567)
    at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.freezeFileTypeTemporarilyIn(FileTypeManagerImpl.java:507)
    at com.intellij.util.indexing.FileBasedIndexImpl.a(FileBasedIndexImpl.java:1528)
    at com.intellij.util.indexing.FileBasedIndexImpl.indexFileContent(FileBasedIndexImpl.java:1513)
    at com.intellij.util.indexing.FileBasedIndexImpl.processRefreshedFile(FileBasedIndexImpl.java:1493)
    at com.intellij.util.indexing.FileBasedIndexProjectHandler.a(FileBasedIndexProjectHandler.java:157)
    at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.a(CacheUpdateRunner.java:235)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1061)
    at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.a(CacheUpdateRunner.java:252)
    at com.intellij.openapi.progress.impl.CoreProgressManager$3.run(CoreProgressManager.java:179)
    at com.intellij.openapi.progress.impl.CoreProgressManager.a(CoreProgressManager.java:568)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:519)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:164)
    at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.run(CacheUpdateRunner.java:248)
    at com.intellij.openapi.application.impl.ApplicationImpl$2.run(ApplicationImpl.java:309)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
manuc66 commented 7 years ago

Hi,

It seem your file /home/dds/dev/go/vendor/github.com/docker/distribution/vendor/gopkg.in/yaml.v2/LICENSE.libyaml is considered as a yaml file due to the fact that its extension ends with yaml.

I would suggest checking the extension this way at org.zalando.intellij.swagger.index.SwaggerFileIndex:

before:

    @NotNull
    @Override
    public FileBasedIndex.InputFilter getInputFilter() {
        return file -> file.getName().endsWith("json")
                || file.getName().endsWith("yaml")
                || file.getName().endsWith("yml");
}

after:

    @NotNull
    @Override
    public FileBasedIndex.InputFilter getInputFilter() {
        return file -> FilenameUtils.isExtension(file.getName(), new String[] {"json", "yaml","yml"});
    }

But it also seems that similar logic is also done in org.zalando.intellij.swagger.file.FileDetector that could potentially be merged.

semonte commented 7 years ago

Sounds like a good plan. As you suggested, we should move the logic to FileDetector with a method isJsonOrYamlFile() or so. @manuc66 do you want to fix this?

We should also use constants found in https://github.com/zalando/intellij-swagger/blob/master/src/main/java/org/zalando/intellij/swagger/file/FileConstants.java