Do not rethrow ProcessCancelledException from ProjectManager

This commit is contained in:
Akash Yadav
2022-07-12 10:42:17 +05:30
parent a361866cb2
commit d48b2d37d5
4 changed files with 17 additions and 24 deletions
+1
View File
@@ -35,6 +35,7 @@ dependencies {
implementation project (path: ':common')
implementation common.io
implementation google.guava
testImplementation project (path: ':build-tools:tooling-api-testing')
@@ -38,11 +38,13 @@ import java.io.BufferedReader
import java.io.File
import java.io.InputStream
import java.io.StringReader
import java.nio.charset.Charset
import java.nio.file.Files
import java.nio.file.Path
import java.time.Instant
import java.util.*
import java.util.concurrent.*
import org.apache.commons.io.FileUtils
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode.BACKGROUND
@@ -335,9 +337,10 @@ object ProjectManager : EventReceiver {
Files.newBufferedReader(file)
} catch (noFile: java.nio.file.NoSuchFileException) {
log.warn("No such file", noFile)
BufferedReader(StringReader(""))
} catch (other: Throwable) {
throw other
"".reader().buffered()
} catch (cancelled: ProcessCancelledException) {
log.debug("createFileReader(): cancelled")
"".reader().buffered()
}
}
@@ -347,8 +350,9 @@ object ProjectManager : EventReceiver {
} catch (noFile: java.nio.file.NoSuchFileException) {
log.warn("No such file", noFile)
"".byteInputStream()
} catch (other: Throwable) {
throw other
} catch (cancelled: ProcessCancelledException) {
log.debug("createFileInputStream(): cancelled")
"".byteInputStream()
}
}
@@ -358,27 +362,14 @@ object ProjectManager : EventReceiver {
private fun getFileContents(file: Path): String {
return try {
val sb = StringBuilder()
createFileReader(file).use {
var line: String?
while (true) {
abortIfCancelled()
line = it.readLine()
if (line == null) {
break
}
sb.append(line)
sb.append("\n")
}
}
sb.toString()
abortIfCancelled()
FileUtils.readFileToString(file.toFile(), Charset.defaultCharset())
} catch (noFile: java.nio.file.NoSuchFileException) {
log.warn("No such file", noFile)
return ""
} catch (other: Throwable) {
throw other
""
} catch (cancelled: ProcessCancelledException) {
log.debug("getFileContents(): cancelled")
""
}
}
}
+1
View File
@@ -16,6 +16,7 @@ ext {
javaparser : 'com.github.javaparser:javaparser-symbol-solver-core:3.24.2',
jsonrpc : 'org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc:0.12.0',
lang3 : 'org.apache.commons:commons-lang3:3.12.0',
io : 'commons-io:commons-io:2.11.0',
kotlin : 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.0',
jkotlin : 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
]
Binary file not shown.