Skip to content

Commit c5a11b5

Browse files
committed
fix: address remaining cursor[bot] review feedback
1. Fix replays download flag: read "output-file" instead of "output" 2. Return proper exit codes in JSON mode for failures: - deploy: return error on failed/stopped deployments - invoke: return error on failed invocations 3. Handle acquire timeout in JSON mode: - browser-pools acquire: output null instead of pterm warning - browsers create (with pool): output null instead of pterm error
1 parent 52b5c9b commit c5a11b5

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

cmd/browser_pools.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ func (c BrowserPoolsCmd) Acquire(ctx context.Context, in BrowserPoolsAcquireInpu
360360
return util.CleanedUpSdkError{Err: err}
361361
}
362362
if resp == nil {
363+
if in.Output == "json" {
364+
fmt.Println("null")
365+
return nil
366+
}
363367
pterm.Warning.Println("Acquire request timed out (no browser available). Retry to continue waiting.")
364368
return nil
365369
}

cmd/browsers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2228,6 +2228,10 @@ func runBrowsersCreate(cmd *cobra.Command, args []string) error {
22282228
return util.CleanedUpSdkError{Err: err}
22292229
}
22302230
if resp == nil {
2231+
if output == "json" {
2232+
fmt.Println("null")
2233+
return nil
2234+
}
22312235
pterm.Error.Println("Acquire request timed out (no browser available). Retry to continue waiting.")
22322236
return nil
22332237
}
@@ -2364,7 +2368,7 @@ func runBrowsersReplaysStop(cmd *cobra.Command, args []string) error {
23642368
func runBrowsersReplaysDownload(cmd *cobra.Command, args []string) error {
23652369
client := getKernelClient(cmd)
23662370
svc := client.Browsers
2367-
out, _ := cmd.Flags().GetString("output")
2371+
out, _ := cmd.Flags().GetString("output-file")
23682372
b := BrowsersCmd{browsers: &svc, replays: &svc.Replays}
23692373
return b.ReplaysDownload(cmd.Context(), BrowsersReplaysDownloadInput{Identifier: args[0], ReplayID: args[1], Output: out})
23702374
}

cmd/deploy.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -531,19 +531,22 @@ func followDeployment(ctx context.Context, client kernel.Client, deploymentID st
531531
if err == nil {
532532
fmt.Println(string(bs))
533533
}
534-
// Check for terminal states
535-
if data.Event == "deployment_state" {
536-
deploymentState := data.AsDeploymentState()
537-
status := deploymentState.Deployment.Status
538-
if status == string(kernel.DeploymentGetResponseStatusFailed) ||
539-
status == string(kernel.DeploymentGetResponseStatusStopped) ||
540-
status == string(kernel.DeploymentGetResponseStatusRunning) {
541-
return nil
542-
}
534+
// Check for terminal states
535+
if data.Event == "deployment_state" {
536+
deploymentState := data.AsDeploymentState()
537+
status := deploymentState.Deployment.Status
538+
if status == string(kernel.DeploymentGetResponseStatusFailed) ||
539+
status == string(kernel.DeploymentGetResponseStatusStopped) {
540+
return fmt.Errorf("deployment %s: %s", status, deploymentState.Deployment.StatusReason)
543541
}
544-
if data.Event == "error" {
542+
if status == string(kernel.DeploymentGetResponseStatusRunning) {
545543
return nil
546544
}
545+
}
546+
if data.Event == "error" {
547+
errorEv := data.AsErrorEvent()
548+
return fmt.Errorf("%s: %s", errorEv.Error.Code, errorEv.Error.Message)
549+
}
547550
continue
548551
}
549552

cmd/invoke.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,21 @@ func runInvoke(cmd *cobra.Command, args []string) error {
180180
if err == nil {
181181
fmt.Println(string(bs))
182182
}
183-
// Check for terminal states
184-
if ev.Event == "invocation_state" {
185-
stateEv := ev.AsInvocationState()
186-
status := stateEv.Invocation.Status
187-
if status == string(kernel.InvocationGetResponseStatusSucceeded) ||
188-
status == string(kernel.InvocationGetResponseStatusFailed) {
189-
return nil
190-
}
191-
}
192-
if ev.Event == "error" {
183+
// Check for terminal states
184+
if ev.Event == "invocation_state" {
185+
stateEv := ev.AsInvocationState()
186+
status := stateEv.Invocation.Status
187+
if status == string(kernel.InvocationGetResponseStatusSucceeded) {
193188
return nil
194189
}
190+
if status == string(kernel.InvocationGetResponseStatusFailed) {
191+
return fmt.Errorf("invocation failed")
192+
}
193+
}
194+
if ev.Event == "error" {
195+
errEv := ev.AsError()
196+
return fmt.Errorf("%s: %s", errEv.Error.Code, errEv.Error.Message)
197+
}
195198
continue
196199
}
197200

0 commit comments

Comments
 (0)