@@ -3,6 +3,7 @@ package com.coder.gateway.sdk
3
3
import com.intellij.openapi.diagnostic.Logger
4
4
import com.intellij.openapi.progress.ProcessCanceledException
5
5
import com.intellij.ssh.SshException
6
+ import com.jetbrains.gateway.ssh.deploy.DeployException
6
7
import kotlinx.coroutines.delay
7
8
import java.util.Random
8
9
import java.util.concurrent.TimeUnit
@@ -19,8 +20,9 @@ fun unwrap(ex: Exception): Throwable? {
19
20
20
21
/* *
21
22
* Similar to Intellij's except it gives you the next delay, logs differently,
22
- * updates periodically (for counting down), runs forever, and takes a
23
- * predicate for determining whether we should retry.
23
+ * updates periodically (for counting down), runs forever, takes a predicate for
24
+ * determining whether we should retry, and has some special handling for
25
+ * exceptions to provide the true cause or better messages.
24
26
*
25
27
* The update will have a boolean to indicate whether it is the first update (so
26
28
* things like duplicate logs can be avoided). If remaining is null then no
@@ -67,7 +69,15 @@ suspend fun <T> suspendingRetryWithExponentialBackOff(
67
69
while (remainingMs > 0 ) {
68
70
val remainingS = TimeUnit .MILLISECONDS .toSeconds(remainingMs)
69
71
val remaining = if (remainingS < 1 ) " now" else " in $remainingS second${if (remainingS > 1 ) " s" else " " } "
70
- update(attempt, unwrappedEx, remaining)
72
+ // When the worker upload times out Gateway just says it failed.
73
+ // Even the root cause (IllegalStateException) is useless. The
74
+ // error also includes a very long useless tmp path. With all
75
+ // that in mind, provide a better error.
76
+ val mungedEx =
77
+ if (unwrappedEx is DeployException && unwrappedEx.message.contains(" Worker binary deploy failed" ))
78
+ DeployException (" Failed to upload worker binary...it may have timed out" , unwrappedEx)
79
+ else unwrappedEx
80
+ update(attempt, mungedEx, remaining)
71
81
val next = min(remainingMs, TimeUnit .SECONDS .toMillis(1 ))
72
82
remainingMs - = next
73
83
delay(next)
0 commit comments