Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
review fixes
  • Loading branch information
kirillk committed Feb 19, 2025
commit 55870c48a1d5b87aab289f10e6cd194b8bd84496
13 changes: 6 additions & 7 deletions src/main/kotlin/com/coder/gateway/CoderRemoteConnectionHandle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,9 @@ class CoderRemoteConnectionHandle {
) {
if (setupCommand.isNotBlank()) {
indicator.text = "Running setup command..."
processSetupCommand(
{ exec(workspace, setupCommand) },
ignoreSetupFailure
)
processSetupCommand(ignoreSetupFailure) {
exec(workspace, setupCommand)
}
} else {
logger.info("No setup command to run on ${workspace.hostname}")
}
Expand Down Expand Up @@ -523,11 +522,11 @@ class CoderRemoteConnectionHandle {
companion object {
val logger = Logger.getInstance(CoderRemoteConnectionHandle::class.java.simpleName)
fun processSetupCommand(
output: () -> String,
ignoreSetupFailure: Boolean
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 this Boolean flag for ignoring errors.

execCommand: () -> String
) {
try {
val errorText = output
val errorText = execCommand
.invoke()
.lines()
.firstOrNull { it.contains(GATEWAY_SETUP_COMMAND_ERROR) }
Expand Down
14 changes: 7 additions & 7 deletions src/test/kotlin/com/coder/gateway/util/SetupCommandTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,36 @@ internal class SetupCommandTest {
assertEquals(
"Execution error",
assertThrows<Exception> {
processSetupCommand({ throw Exception("Execution error") }, false)
processSetupCommand(false) { throw Exception("Execution error") }
}.message
)
processSetupCommand({ throw Exception("Execution error") }, true)
processSetupCommand(true) { throw Exception("Execution error") }
}

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

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

}
}