Skip to content

Commit 5164aff

Browse files
committed
Propagate non-zero exit code as exceptions
Otherwise they will not be visible to the user. This is particularly important as it will probably be easy for a user to make a typo when overriding the binary URL and hit something that gives a 200 but is not actually the binary.
1 parent 3ab88be commit 5164aff

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ class CoderCLIManager @JvmOverloads constructor(
291291
private fun exec(vararg args: String): String {
292292
val stdout = ProcessExecutor()
293293
.command(localBinaryPath.toString(), *args)
294+
.exitValues(0)
294295
.readOutput(true)
295296
.execute()
296297
.outputUTF8()

src/test/groovy/CoderCLIManagerTest.groovy

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import com.coder.gateway.sdk.v2.models.WorkspaceTransition
77
import com.sun.net.httpserver.HttpExchange
88
import com.sun.net.httpserver.HttpHandler
99
import com.sun.net.httpserver.HttpServer
10+
import org.zeroturnaround.exec.InvalidExitValueException
11+
import org.zeroturnaround.exec.ProcessInitException
1012
import spock.lang.Requires
1113
import spock.lang.Shared
1214
import spock.lang.Specification
@@ -140,6 +142,13 @@ class CoderCLIManagerTest extends Specification {
140142
then:
141143
downloaded
142144
ccm.version().contains("Coder")
145+
146+
// Make sure login failures propagate correctly.
147+
when:
148+
ccm.login("jetbrains-ci-test")
149+
150+
then:
151+
thrown(InvalidExitValueException)
143152
}
144153

145154
def "downloads a mocked cli"() {
@@ -162,6 +171,17 @@ class CoderCLIManagerTest extends Specification {
162171
srv.stop(0)
163172
}
164173

174+
def "fails to run non-existent binary"() {
175+
given:
176+
def ccm = new CoderCLIManager(new URL("https://foo"), tmpdir.resolve("does-not-exist"))
177+
178+
when:
179+
ccm.version()
180+
181+
then:
182+
thrown(ProcessInitException)
183+
}
184+
165185
def "overwrites cli if incorrect version"() {
166186
given:
167187
def (srv, url) = mockServer()

0 commit comments

Comments
 (0)