Skip to content

Commit 3245c4f

Browse files
Fix: catch error when notification file is not found (#5157)
* handle uncaught error * detekt
1 parent 38ac5fe commit 3245c4f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/ProcessNotificationsBase.kt

+10-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import com.intellij.openapi.project.Project
1616
import software.aws.toolkits.core.utils.getLogger
1717
import software.aws.toolkits.core.utils.info
1818
import software.aws.toolkits.core.utils.inputStream
19+
import software.aws.toolkits.core.utils.warn
1920
import software.aws.toolkits.jetbrains.utils.notifyStickyWithData
2021
import java.nio.file.Paths
2122
import java.util.concurrent.atomic.AtomicBoolean
@@ -38,12 +39,17 @@ class ProcessNotificationsBase(
3839
}
3940

4041
private fun getNotificationsFromFile(): NotificationsList? {
41-
val path = Paths.get(PathManager.getSystemPath(), NOTIFICATIONS_PATH)
42-
val content = path.inputStream().bufferedReader().use { it.readText() }
43-
if (content.isEmpty()) {
42+
try {
43+
val path = Paths.get(PathManager.getSystemPath(), NOTIFICATIONS_PATH)
44+
val content = path.inputStream().bufferedReader().use { it.readText() }
45+
if (content.isEmpty()) {
46+
return null
47+
}
48+
return NotificationMapperUtil.mapper.readValue(content)
49+
} catch (e: Exception) {
50+
LOG.warn { "Error reading notifications file: $e" }
4451
return null
4552
}
46-
return NotificationMapperUtil.mapper.readValue(content)
4753
}
4854

4955
fun retrieveStartupAndEmergencyNotifications() {

0 commit comments

Comments
 (0)