Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

setup script can communicate an error message to the end user#538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bcpeinhardt merged 6 commits intocoder:mainfromkirillk:kkalishev/setup-script-error
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletionsCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,10 @@

## Unreleased

### Added

- Added functionality to show setup script error message to the end user.

### Fixed

- Fix bug where wildcard configs would not be written under certain conditions.
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,4 +3,5 @@ package com.coder.gateway
object CoderGatewayConstants {
const val GATEWAY_CONNECTOR_ID = "Coder.Gateway.Connector"
const val GATEWAY_RECENT_CONNECTIONS_ID = "Coder.Gateway.Recent.Connections"
const val GATEWAY_SETUP_COMMAND_ERROR = "CODER_SETUP_ERROR"
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@

package com.coder.gateway

import com.coder.gateway.CoderGatewayConstants.GATEWAY_SETUP_COMMAND_ERROR
import com.coder.gateway.cli.CoderCLIManager
import com.coder.gateway.models.WorkspaceProjectIDE
import com.coder.gateway.models.toIdeWithStatus
Expand DownExpand Up@@ -160,25 +161,38 @@ class CoderRemoteConnectionHandle {
)
logger.info("Adding ${parameters.ideName} for ${parameters.hostname}:${parameters.projectPath} to recent connections")
recentConnectionsService.addRecentConnection(parameters.toRecentWorkspaceConnection())
} catch (e: CoderSetupCommandException) {
logger.error("Failed to run setup command", e)
showConnectionErrorMessage(
e.message ?: "Unknown error",
"gateway.connector.coder.setup-command.failed",
)
} catch (e: Exception) {
if (isCancellation(e)) {
logger.info("Connection canceled due to ${e.javaClass.simpleName}")
} else {
logger.error("Failed to connect (will not retry)", e)
// The dialog will close once we return so write the error
// out into a new dialog.
ApplicationManager.getApplication().invokeAndWait {
Messages.showMessageDialog(
e.message ?: e.javaClass.simpleName ?: "Aborted",
CoderGatewayBundle.message("gateway.connector.coder.connection.failed"),
Messages.getErrorIcon(),
)
}
showConnectionErrorMessage(
e.message ?: e.javaClass.simpleName ?: "Aborted",
"gateway.connector.coder.connection.failed"
)
}
}
}
}

// The dialog will close once we return so write the error
// out into a new dialog.
private fun showConnectionErrorMessage(message: String, titleKey: String) {
ApplicationManager.getApplication().invokeAndWait {
Messages.showMessageDialog(
message,
CoderGatewayBundle.message(titleKey),
Messages.getErrorIcon(),
)
}
}

/**
* Return a new (non-EAP) IDE if we should update.
*/
Expand DownExpand Up@@ -412,18 +426,15 @@ class CoderRemoteConnectionHandle {
) {
if (setupCommand.isNotBlank()) {
indicator.text = "Running setup command..."
try {
processSetupCommand(ignoreSetupFailure) {
exec(workspace, setupCommand)
} catch (ex: Exception) {
if (!ignoreSetupFailure) {
throw ex
}
}
} else {
logger.info("No setup command to run on ${workspace.hostname}")
}
}


/**
* Execute a command in the IDE's bin directory.
* This exists since the accessor does not provide a generic exec.
Expand DownExpand Up@@ -523,5 +534,26 @@ class CoderRemoteConnectionHandle {

companion object {
val logger = Logger.getInstance(CoderRemoteConnectionHandle::class.java.simpleName)
@Throws(CoderSetupCommandException::class)
fun processSetupCommand(
ignoreSetupFailure: Boolean,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Not a comment on this PR just a note to self about how we're doing this in general: don't love us drilling down thisBoolean flag for ignoring errors.

execCommand: () -> String
) {
try {
val errorText = execCommand
.invoke()
.lines()
.firstOrNull { it.contains(GATEWAY_SETUP_COMMAND_ERROR) }
?.let { it.substring(it.indexOf(GATEWAY_SETUP_COMMAND_ERROR) + GATEWAY_SETUP_COMMAND_ERROR.length).trim() }

if (!errorText.isNullOrBlank()) {
throw CoderSetupCommandException(errorText)
}
} catch (ex: Exception) {
if (!ignoreSetupFailure) {
throw CoderSetupCommandException(ex.message ?: "Unknown error", ex)
}
}
}
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
package com.coder.gateway

class CoderSetupCommandException : Exception {

constructor(message: String) : super(message)
constructor(message: String, cause: Throwable) : super(message, cause)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

a more simpler approach:

class CoderSetupCommandException(message: String, cause: Throwable? = null) : Exception(message, cause)

}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,6 +49,7 @@ gateway.connector.coder.connection.provider.title=Connecting to Coder workspace.
gateway.connector.coder.connecting=Connecting...
gateway.connector.coder.connecting.retry=Connecting (attempt {0})...
gateway.connector.coder.connection.failed=Failed to connect
gateway.connector.coder.setup-command.failed=Failed to set up backend IDE
gateway.connector.coder.connecting.failed.retry=Failed to connect...retrying {0}
gateway.connector.settings.data-directory.title=Data directory
gateway.connector.settings.data-directory.comment=Directories are created \
Expand Down
48 changes: 48 additions & 0 deletionssrc/test/kotlin/com/coder/gateway/util/SetupCommandTest.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
package com.coder.gateway.util

import com.coder.gateway.CoderRemoteConnectionHandle.Companion.processSetupCommand
import com.coder.gateway.CoderSetupCommandException
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import kotlin.test.assertEquals

internal class SetupCommandTest {

@Test
fun executionErrors() {
assertEquals(
"Execution error",
assertThrows<CoderSetupCommandException> {
processSetupCommand(false) { throw Exception("Execution error") }
}.message
)
processSetupCommand(true) { throw Exception("Execution error") }
}

@Test
fun setupScriptError() {
assertEquals(
"Your IDE is expired, please update",
assertThrows<CoderSetupCommandException> {
processSetupCommand(false) {
"""
execution line 1
execution line 2
CODER_SETUP_ERRORYour IDE is expired, please update
execution line 3
"""
}
}.message
)

processSetupCommand(true) {
"""
execution line 1
execution line 2
CODER_SETUP_ERRORYour IDE is expired, please update
execution line 3
"""
}

}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp