Skip to content

Commit 4e5206e

Browse files
committed
Provide better error when dd times out
1 parent 405fb43 commit 4e5206e

File tree

1 file changed

+13
-3
lines changed
  • src/main/kotlin/com/coder/gateway/sdk

1 file changed

+13
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.coder.gateway.sdk
33
import com.intellij.openapi.diagnostic.Logger
44
import com.intellij.openapi.progress.ProcessCanceledException
55
import com.intellij.ssh.SshException
6+
import com.jetbrains.gateway.ssh.deploy.DeployException
67
import kotlinx.coroutines.delay
78
import java.util.Random
89
import 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

Comments
 (0)