Skip to content

Commit 78f7a0c

Browse files
committed
catch exceptions in settings changed
1 parent 785b3f8 commit 78f7a0c

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/updates/AggressiveUpdateService.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,22 @@ class AggressiveUpdateService : Disposable {
116116

117117
@Suppress("UnstableApiUsage")
118118
disposingScope().launch {
119-
//update state immediately after settings change. we are interested in api url change but it will
120-
// do no harm to call it on any settings change
121-
updateState()
119+
try {
120+
//update state immediately after settings change. we are interested in api url change, but it will
121+
// do no harm to call it on any settings change
122+
updateState()
123+
} catch (c: CancellationException) {
124+
Log.debugWithException(logger, c, "settings change canceled {}", c)
125+
} catch (e: Throwable) {
126+
val message = ExceptionUtils.getNonEmptyMessage(e)
127+
Log.debugWithException(logger, e, "error in settings changed {}", message)
128+
errorReporter.reportError("${this::class.simpleName}.settingsChange", e)
129+
}
130+
122131
//and call startMonitoring just in case it is stopped by a previous connectionLost but there was no connection gained
123132
startMonitoring()
124133
}
134+
125135
}, this)
126136

127137
} else {

ide-common/src/main/kotlin/org/digma/intellij/plugin/updates/UpdatesService.kt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,33 @@ class UpdatesService(private val project: Project) : Disposable {
9393

9494
override fun connectionGained() {
9595
Log.log(logger::debug, "got connectionGained")
96-
//update state immediately after connectionGained, so it will not wait the delay for checking the versions.
97-
checkForNewerVersions()
96+
97+
try {
98+
//update state immediately after connectionGained, so it will not wait the delay for checking the versions.
99+
checkForNewerVersions()
100+
} catch (e: CancellationException) {
101+
Log.debugWithException(logger, e, "Exception in checkForNewerVersions")
102+
} catch (e: Throwable) {
103+
Log.debugWithException(logger, e, "Exception in checkForNewerVersions {}", ExceptionUtils.getNonEmptyMessage(e))
104+
ErrorReporter.getInstance().reportError("UpdatesService.connectionGained", e)
105+
}
98106
}
99107
})
100108

101109

102110
SettingsState.getInstance().addChangeListener({
103111
@Suppress("UnstableApiUsage")
104112
disposingScope().launch {
105-
//update state immediately after settings change. we are interested in api url change, but it will
106-
// do no harm to call it on any settings change
107-
checkForNewerVersions()
113+
try {
114+
//update state immediately after settings change. we are interested in api url change, but it will
115+
// do no harm to call it on any settings change
116+
checkForNewerVersions()
117+
} catch (e: CancellationException) {
118+
Log.debugWithException(logger, e, "Exception in checkForNewerVersions")
119+
} catch (e: Throwable) {
120+
Log.debugWithException(logger, e, "Exception in checkForNewerVersions {}", ExceptionUtils.getNonEmptyMessage(e))
121+
ErrorReporter.getInstance().reportError("UpdatesService.settingsChanged", e)
122+
}
108123
}
109124

110125
}, this)
@@ -114,6 +129,7 @@ class UpdatesService(private val project: Project) : Disposable {
114129
//nothing to do , used as parent disposable
115130
}
116131

132+
//this method may throw exception, always catch and report
117133
private fun checkForNewerVersions() {
118134

119135
Log.log(logger::trace, "checking for new versions")

0 commit comments

Comments
 (0)