Skip to content

Commit 670954e

Browse files
committed
Surface connection status and errors in table
Instead of just "Nothing to show" it will show the last error or the status if we are currently trying to connect.
1 parent 2f82918 commit 670954e

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

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

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import com.intellij.openapi.components.service
3838
import com.intellij.openapi.diagnostic.Logger
3939
import com.intellij.openapi.rd.util.launchUnderBackgroundProgress
4040
import com.intellij.openapi.ui.panel.ComponentPanelBuilder
41+
import com.intellij.openapi.ui.setEmptyState
4142
import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
4243
import com.intellij.ui.AnActionButton
4344
import com.intellij.ui.AppIcon
@@ -76,6 +77,7 @@ import java.awt.event.MouseListener
7677
import java.awt.event.MouseMotionListener
7778
import java.awt.font.TextAttribute
7879
import java.awt.font.TextAttribute.UNDERLINE_ON
80+
import java.net.ConnectException
7981
import java.net.SocketTimeoutException
8082
import java.net.URL
8183
import java.nio.file.Path
@@ -126,6 +128,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
126128
minWidth = JBUI.scale(52)
127129
}
128130
rowHeight = 48
131+
setEmptyState("Disconnected")
129132
setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
130133
selectionModel.addListSelectionListener {
131134
setNextButtonEnabled(selectedObject != null && selectedObject?.agentStatus == RUNNING && selectedObject?.agentOS == OS.LINUX)
@@ -444,6 +447,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
444447
private fun connect(deploymentURL: URL, token: String, onAuthFailure: (() -> Unit)? = null): Job {
445448
// Clear out old deployment details.
446449
poller?.cancel()
450+
tableOfWorkspaces.setEmptyState("Connecting to $deploymentURL...")
447451
listTableModelOfWorkspaces.items = emptyList()
448452

449453
// Authenticate and load in a background process with progress.
@@ -453,6 +457,12 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
453457
canBeCancelled = false,
454458
isIndeterminate = true
455459
) {
460+
val cliManager = CoderCLIManager(
461+
deploymentURL,
462+
if (settings.binaryDestination.isNotBlank()) Path.of(settings.binaryDestination)
463+
else CoderCLIManager.getDataDir(),
464+
settings.binarySource,
465+
)
456466
try {
457467
this.indicator.text = "Authenticating client..."
458468
authenticate(deploymentURL, token)
@@ -461,12 +471,6 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
461471
appPropertiesService.setValue(SESSION_TOKEN, token)
462472

463473
this.indicator.text = "Downloading Coder CLI..."
464-
val cliManager = CoderCLIManager(
465-
deploymentURL,
466-
if (settings.binaryDestination.isNotBlank()) Path.of(settings.binaryDestination)
467-
else CoderCLIManager.getDataDir(),
468-
settings.binarySource,
469-
)
470474
cliManager.downloadCLI()
471475

472476
this.indicator.text = "Authenticating Coder CLI..."
@@ -477,17 +481,41 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
477481

478482
updateWorkspaceActions()
479483
triggerWorkspacePolling(false)
480-
} catch (e: AuthenticationResponseException) {
481-
logger.error("Token was rejected by $deploymentURL; has your token expired?", e)
482-
if (retry) {
483-
askTokenAndConnect(false) // Try again but no more opening browser windows.
484-
}
485-
} catch (e: SocketTimeoutException) {
486-
logger.error("Unable to connect to $deploymentURL; is it up?", e)
487-
} catch (e: ResponseException) {
488-
logger.error("Failed to download Coder CLI", e)
484+
485+
tableOfWorkspaces.setEmptyState("Connected to $deploymentURL")
489486
} catch (e: Exception) {
490-
logger.error("Failed to configure connection to $deploymentURL", e)
487+
val errorSummary = e.message ?: "No reason was provided"
488+
var msg = CoderGatewayBundle.message(
489+
"gateway.connector.view.workspaces.connect.failed",
490+
deploymentURL,
491+
errorSummary,
492+
)
493+
when (e) {
494+
is AuthenticationResponseException -> {
495+
msg = CoderGatewayBundle.message(
496+
"gateway.connector.view.workspaces.connect.unauthorized",
497+
deploymentURL,
498+
)
499+
cs.launch { onAuthFailure?.invoke() }
500+
}
501+
502+
is SocketTimeoutException -> {
503+
msg = CoderGatewayBundle.message(
504+
"gateway.connector.view.workspaces.connect.timeout",
505+
deploymentURL,
506+
)
507+
}
508+
509+
is ResponseException, is ConnectException -> {
510+
msg = CoderGatewayBundle.message(
511+
"gateway.connector.view.workspaces.connect.download-failed",
512+
cliManager.remoteBinaryURL,
513+
errorSummary,
514+
)
515+
}
516+
}
517+
tableOfWorkspaces.setEmptyState(msg)
518+
logger.error(msg, e)
491519
}
492520
}
493521
}

src/main/resources/messages/CoderGatewayBundle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ gateway.connector.view.coder.workspaces.create.text=Create workspace
2020
gateway.connector.view.coder.workspaces.unsupported.os.info=Gateway supports only Linux machines. Support for macOS and Windows is planned.
2121
gateway.connector.view.coder.workspaces.invalid.coder.version=Could not parse Coder version {0}. Coder Gateway plugin might not be compatible with this version. <a href='https://coder.com/docs/coder-oss/latest/ides/gateway#creating-a-new-jetbrains-gateway-connection'>Connect to a Coder workspace manually</a>
2222
gateway.connector.view.coder.workspaces.unsupported.coder.version=Coder version {0} might not be compatible with this plugin version. <a href='https://coder.com/docs/coder-oss/latest/ides/gateway#creating-a-new-jetbrains-gateway-connection'>Connect to a Coder workspace manually</a>
23+
gateway.connector.view.workspaces.connect.unauthorized=Token was rejected by {0}; has your token expired?
24+
gateway.connector.view.workspaces.connect.timeout=Unable to connect to {0}; is it up?
25+
gateway.connector.view.workspaces.connect.download-failed=Failed to download Coder CLI from {0}: {1}
26+
gateway.connector.view.workspaces.connect.failed=Failed to configure connection to {0}: {1}
2327
gateway.connector.view.coder.remoteproject.loading.text=Retrieving products...
2428
gateway.connector.view.coder.remoteproject.ide.error.text=Could not retrieve any IDE because an error was encountered. Please check the logs for more details!
2529
gateway.connector.view.coder.remoteproject.ssh.error.text=Can't connect to the workspace. Please make sure Coder Agent is running!

0 commit comments

Comments
 (0)