Skip to content

Commit 1a67157

Browse files
committed
Munge error at point of display
1 parent f417542 commit 1a67157

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/main/kotlin/com/coder/gateway/CoderGatewayConnectionProvider.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.coder.gateway
44

55
import com.coder.gateway.sdk.humanizeDuration
6+
import com.coder.gateway.sdk.isWorkerTimeout
67
import com.coder.gateway.sdk.suspendingRetryWithExponentialBackOff
78
import com.coder.gateway.services.CoderRecentWorkspaceConnectionsService
89
import com.intellij.openapi.application.ApplicationManager
@@ -48,7 +49,9 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
4849
},
4950
update = { _, e, remainingMs ->
5051
if (remainingMs != null) {
51-
indicator.text2 = e.message ?: CoderGatewayBundle.message("gateway.connector.no-details")
52+
indicator.text2 =
53+
if (isWorkerTimeout(e)) "Failed to upload worker binary...it may have timed out"
54+
else e.message ?: CoderGatewayBundle.message("gateway.connector.no-details")
5255
indicator.text = CoderGatewayBundle.message("gateway.connector.coder.connection.retry-error.text", humanizeDuration(remainingMs))
5356
} else {
5457
ApplicationManager.getApplication().invokeAndWait {

src/main/kotlin/com/coder/gateway/sdk/Retry.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,7 @@ suspend fun <T> suspendingRetryWithExponentialBackOff(
6767
logger.error("Failed to $label (attempt $attempt; will retry in $delayMs ms)", originalEx)
6868
var remainingMs = delayMs
6969
while (remainingMs > 0) {
70-
// When the worker upload times out Gateway just says it failed.
71-
// Even the root cause (IllegalStateException) is useless. The
72-
// error also includes a very long useless tmp path. With all
73-
// that in mind, provide a better error.
74-
val mungedEx =
75-
if (unwrappedEx is DeployException && unwrappedEx.message.contains("Worker binary deploy failed"))
76-
DeployException("Failed to upload worker binary...it may have timed out", unwrappedEx)
77-
else unwrappedEx
78-
update(attempt, mungedEx, remainingMs)
70+
update(attempt, unwrappedEx, remainingMs)
7971
val next = min(remainingMs, TimeUnit.SECONDS.toMillis(1))
8072
remainingMs -= next
8173
delay(next)
@@ -97,3 +89,12 @@ fun humanizeDuration(durationMs: Long): String {
9789
val seconds = TimeUnit.MILLISECONDS.toSeconds(durationMs)
9890
return if (seconds < 1) "now" else "in $seconds second${if (seconds > 1) "s" else ""}"
9991
}
92+
93+
/**
94+
* When the worker upload times out Gateway just says it failed. Even the root
95+
* cause (IllegalStateException) is useless. The error also includes a very
96+
* long useless tmp path. Return true if the error looks like this timeout.
97+
*/
98+
fun isWorkerTimeout(e: Throwable): Boolean {
99+
return e is DeployException && e.message.contains("Worker binary deploy failed")
100+
}

src/main/kotlin/com/coder/gateway/views/steps/CoderLocateRemoteProjectStepView.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.coder.gateway.sdk.CoderCLIManager
99
import com.coder.gateway.sdk.CoderRestClientService
1010
import com.coder.gateway.sdk.OS
1111
import com.coder.gateway.sdk.humanizeDuration
12+
import com.coder.gateway.sdk.isWorkerTimeout
1213
import com.coder.gateway.sdk.suspendingRetryWithExponentialBackOff
1314
import com.coder.gateway.sdk.toURL
1415
import com.coder.gateway.sdk.withPath
@@ -200,7 +201,9 @@ class CoderLocateRemoteProjectStepView(private val setNextButtonEnabled: (Boolea
200201
},
201202
update = { _, e, remainingMs ->
202203
cbIDEComment.foreground = UIUtil.getErrorForeground()
203-
cbIDEComment.text = e.message ?: CoderGatewayBundle.message("gateway.connector.no-details")
204+
cbIDEComment.text =
205+
if (isWorkerTimeout(e)) "Failed to upload worker binary...it may have timed out. Check the command log for more details."
206+
else e.message ?: CoderGatewayBundle.message("gateway.connector.no-details")
204207
cbIDE.renderer =
205208
if (remainingMs != null) IDECellRenderer(CoderGatewayBundle.message("gateway.connector.view.coder.remoteproject.retry-error.text", humanizeDuration(remainingMs)))
206209
else IDECellRenderer(CoderGatewayBundle.message("gateway.connector.view.coder.remoteproject.error.text"), UIUtil.getBalloonErrorIcon())

0 commit comments

Comments
 (0)