From 86ef0d5a0e22fc708d5efed6078683cc9aad62a7 Mon Sep 17 00:00:00 2001 From: Bogdan Kirilenko Date: Tue, 15 Oct 2024 16:53:22 +0200 Subject: [PATCH] [PyCharm] PY-73511 Fix HF module error if the user is isolated from the internet by error catching GitOrigin-RevId: 736943f685e7825b4547b13d4fee405f428b5fc0 --- .../impl/huggingFace/api/HuggingFaceHttpClient.kt | 5 ++--- .../service/HuggingFaceImportedLibrariesManager.kt | 11 ++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/api/HuggingFaceHttpClient.kt b/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/api/HuggingFaceHttpClient.kt index b4958a5ffa76..99dd7eb455b9 100644 --- a/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/api/HuggingFaceHttpClient.kt +++ b/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/api/HuggingFaceHttpClient.kt @@ -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) - //} } } diff --git a/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/service/HuggingFaceImportedLibrariesManager.kt b/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/service/HuggingFaceImportedLibrariesManager.kt index 6566cdeed8f0..786a45f85658 100644 --- a/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/service/HuggingFaceImportedLibrariesManager.kt +++ b/python/huggingFace/src/com/intellij/python/community/impl/huggingFace/service/HuggingFaceImportedLibrariesManager.kt @@ -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) { - 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) } } }