[PyCharm] PY-73511 Fix HF module error if the user is isolated from the internet by error catching

GitOrigin-RevId: 736943f685e7825b4547b13d4fee405f428b5fc0
This commit is contained in:
Bogdan Kirilenko
2024-10-15 17:53:23 +00:00
committed by intellij-monorepo-bot
parent 1fd98673ae
commit 86ef0d5a0e
2 changed files with 10 additions and 6 deletions
@@ -28,9 +28,8 @@ object HuggingFaceHttpClient {
val linkHeader = connection.getHeaderField("Link")
connection.disconnect()
HfHttpResponseWithHeaders(content, linkHeader)
}.onFailure {
thisLogger().warn("Failed to download: $url", it)
}
//}.onFailure {
// thisLogger().warn("Failed to download: $url", it)
//}
}
}
@@ -3,6 +3,7 @@ package com.intellij.python.community.impl.huggingFace.service
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.Service
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.editor.event.DocumentEvent
import com.intellij.openapi.editor.event.DocumentListener
@@ -122,9 +123,13 @@ private class HuggingFaceFileChangesListener(private val onThresholdReached: ()
private var fileChangesCounter = 0
override fun after(events: List<VFileEvent>) {
if (events.any { it.file?.extension in listOf("py", "ipynb") }) {
fileChangesCounter++
if (fileChangesCounter >= HuggingFaceLibrariesManagerConfig.CHANGES_NUM_THRESHOLD) onThresholdReached()
try {
if (events.any { it.file?.extension in listOf("py", "ipynb") }) {
fileChangesCounter++
if (fileChangesCounter >= HuggingFaceLibrariesManagerConfig.CHANGES_NUM_THRESHOLD) onThresholdReached()
}
} catch (e: Exception) {
thisLogger().warn("Exception in HuggingFaceFileChangesListener.after", e)
}
}
}