@@ -3,6 +3,7 @@ package com.coder.gateway.sdk
33import com.intellij.openapi.diagnostic.Logger
44import com.intellij.openapi.progress.ProcessCanceledException
55import com.intellij.ssh.SshException
6+ import com.jetbrains.gateway.ssh.deploy.DeployException
67import kotlinx.coroutines.delay
78import java.util.Random
89import java.util.concurrent.TimeUnit
@@ -19,8 +20,9 @@ fun unwrap(ex: Exception): Throwable? {
1920
2021/* *
2122 * 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.
2426 *
2527 * The update will have a boolean to indicate whether it is the first update (so
2628 * things like duplicate logs can be avoided). If remaining is null then no
@@ -67,7 +69,15 @@ suspend fun <T> suspendingRetryWithExponentialBackOff(
6769 while (remainingMs > 0 ) {
6870 val remainingS = TimeUnit .MILLISECONDS .toSeconds(remainingMs)
6971 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)
7181 val next = min(remainingMs, TimeUnit .SECONDS .toMillis(1 ))
7282 remainingMs - = next
7383 delay(next)
0 commit comments