- Notifications
You must be signed in to change notification settings - Fork16
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
88134ba
55870c4
eb5e2ac
c0b6fea
e3a37fb
acc6a7f
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
@@ -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) | ||
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. | ||
*/ | ||
@@ -412,18 +426,15 @@ class CoderRemoteConnectionHandle { | ||
) { | ||
if (setupCommand.isNotBlank()) { | ||
indicator.text = "Running setup command..." | ||
processSetupCommand(ignoreSetupFailure) { | ||
exec(workspace, setupCommand) | ||
} | ||
} 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. | ||
@@ -523,5 +534,26 @@ class CoderRemoteConnectionHandle { | ||
companion object { | ||
val logger = Logger.getInstance(CoderRemoteConnectionHandle::class.java.simpleName) | ||
@Throws(CoderSetupCommandException::class) | ||
fun processSetupCommand( | ||
ignoreSetupFailure: Boolean, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 this | ||
execCommand: () -> String | ||
) { | ||
try { | ||
val errorText = execCommand | ||
.invoke() | ||
kirillk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
.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) | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} |
Original file line number | Diff line number | Diff 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 | ||
""" | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading.Please reload this page.